我可以在 Google TV 上成功播放 HLS(IPTV)视频流,但是视频播放时有些模糊(屏幕底部出现模糊线),谁能帮我避免这个?是否有任何解决问题,如果有如何避免?
这是我的代码:
public class HLSActivity extends Activity
implements AudioManager.OnAudioFocusChangeListener, MediaPlayer.OnCompletionListener,
MediaPlayer.OnErrorListener {
public static final String TAG = "VPActivity";
Button button;
public VideoView mVideoView = null;
private LayoutParams mDefaultVideoViewSize;
// Handle AudioFocus issues
@Override
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;
}
}
@Override
public void onCompletion(MediaPlayer mp) {
Log.i(TAG, "done.");
mVideoView = null;
this.finish();
}
@Override
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);
setContentView(R.layout.activity_sandbox);
// 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.
}
mVideoView = (VideoView) findViewById(R.id.videoView);
mVideoView.setVideoPath("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
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();
mDefaultVideoViewSize = mVideoView.getLayoutParams();
}
}
我的 LayoutXML 是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>