I downloaded the googletv-video-player example and picked only the VideoPlayerActivity as i was only interested in how to play streams.
I modified its xml & java files to play the video in full Screen mode.
here is what i have now:
player.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:padding="10dp">
<VideoView android:id="@+id/videoViewFullScreen"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
player.java
public class player extends Activity implements
AudioManager.OnAudioFocusChangeListener,
MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
public static final String TAG = "VPActivity";
public VideoView mVideoView = null;
// Handle AudioFocus issues
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
Log.i(TAG, "AF Gain");
if (mVideoView != null)
mVideoView.resume();
break;
case AudioManager.AUDIOFOCUS_LOSS:
Log.i(TAG, "AF Loss");
if (mVideoView != null)
mVideoView.stopPlayback();
mVideoView = null;
this.finish(); // Let's move on.
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
Log.i(TAG, "AF Transient");
if (mVideoView != null)
mVideoView.pause();
break;
}
}
public void onCompletion(MediaPlayer mp) {
Log.i(TAG, "done.");
mVideoView = null;
this.finish();
}
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.e(TAG, "IO Error e=" + what + " x=" + extra);
return false; // Will call onCompletion
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Request Audio Focus
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int result = am.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.e(TAG, "Can't get AudioFocus " + result);
this.finish(); // Just give up.
}
//added the following to make video large, hide title and keep activity alive
//---------------------------------------------------------------------------
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//----------------------------------------------------------------
setContentView(R.layout.player);
mVideoView = (VideoView) findViewById(R.id.videoViewFullScreen);
mVideoView.setVideoPath("rtsp://stream-url");
mVideoView.setOnCompletionListener(this);
mVideoView.setOnErrorListener(this);
MediaController mc = new MediaController(this, true);
mc.setMediaPlayer(mVideoView);
mc.setAnchorView(mVideoView);
mVideoView.setMediaController(mc);
mVideoView.requestFocus();
mVideoView.start();
}
}
Now I am having TWO issues
One on Motorola Xoom Tablet and
Second on Google TV
Issue on Tablet (Android version: 4.0.3) This is a small issue. Tablet begins streaming video properly. It plays the video for 15-20 minutes perfectly. but after some time, the video stops playing. I checked its state by tapping on the screen and i realized that the player was automatically Stopped.!
When i tapped on Play again.. it began playing stream perfectly. Why does it stop automatically???
Issue on Google TV (Android version: 3.1)
This is a more serious issue. First the google tv was not playing it at all and would give me the following error:
Cannot Play Video
-----------------------------------------
Sorry, this video cannot be played.
Edit: Now this issue has disappeared and video is played....i did nothing. But y was it behaving in such way??
Now the issue is that Google TV screen only shows the 1/4th part of the video at upper left corner and the remaining video is hidden.... as if the VideoView object is stretched while some other object is on top of it with an open window on upper left corner and it hiding the VideoView
AND the player activity finishes automatically.
The video even plays in emulator & tablet so i cannot paste the error generated by the emulator (as there is no error there) from LogCat.
My Android application is built with Android 3.1 library
I tried your code on GoogleTV and it works fine. The only thing I suggest you need to change for streaming url is this line:
mVideoView.setVideoPath("rtsp://stream-url");
The above is for playing local files, for streaming urls use the following instead:
mVideoView.setVideoURI(Uri.parse("rtsp://stream-url"));