嗨在我的android應用程序中,我使用videoview來流式傳輸視頻。我面臨來自我的視頻非常不受歡迎的行爲。情景就是這樣。我有活動A和活動B.活動A有一個簡單的按鈕,點擊該按鈕後,我開始包含videoview的活動B,並在開始活動後立即開始播放視頻。所以我的觀察是這樣的:一旦我開始活動B,它會調用setVideoURI
和start()
。有幾個回調方法其中之一是setOnPreparedListener
。當我在一段時間後撥打start()
它正在執行setOnPreparedListener
,之後它將開始播放視頻。但是在執行setOnPreparedListener
之前,如果我回到活動A,它會阻止該活動UI一段時間。但如果我等到setOnPreparedListener
得到執行,然後回到活動A,那麼它的工作正常。所有設備都不會出現這種情況,只能使用谷歌設備,如moto g和nexus。但我嘗試過使用htc或intel設備,它工作正常。我的代碼看起來像:安卓視頻導致阻塞用戶界面元素
VideoView mVideoView =(VideoView)findViewById(R.id.myVideo);
//Creating MediaController
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(mVideoView);
//specify the location of media file
Uri uri=Uri.parse("http://abcExample.com/playlist.m3u8");
//Setting MediaController and URI, then starting the videoView
mVideoView.setMediaController(mediaController);
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();
mVideoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.i("this is video view sample ... ", "this is video view sample ... this is on error listener ");
return true;
}
});
mVideoView.setOnPreparedListener(new OnPreparedListener()
{
@Override
public void onPrepared(MediaPlayer mp)
{
Log.i("this is video view sample ... ", "this is video view sample ... this is on prepared listener ");
}
});
mVideoView.setOnCompletionListener(new OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
Log.i("this is video view sample ... ", "this is video view sample ... this is on complete listener ");
}
});
我錯過了什麼或做錯了什麼?需要一些幫助。謝謝。
有人知道嗎? – nilkash 2014-10-06 09:30:06
我已經測試了mp4和hls視頻。對於hls視頻來說,它會給出這個問題,否則對於mp4來說它的工作正常。 – nilkash 2014-10-06 09:51:01