MediaPlayer的冻结而不是在Android 4.4的循环视频 [英] MediaPlayer freezes instead of looping video on Android 4.4
问题描述
我有对Galaxy Tab的3对Android 4.4的视频播放问题并没有随着$ P $会出现此问题pvious Android版本4.2。
I am having a problem with video playback on Android 4.4 on the Galaxy Tab 3. The issue did not occur with the previous Android version 4.2.
问题
我在玩一个循环的视频。这个工作非常出色为所有用户,直到标签3得到更新到Android 4.4。自那时以来,视频第一循环结束后冻结(它卡住视频的第一帧是precise)。
I am playing a video in a loop. This worked very well for all users, until the Tab 3 got updated to Android 4.4. Since then the video freezes after the first loop (it gets stuck on the first frame of the video to be precise).
我可以重现行为,而此刻的视频冻结我的LogCat中开始变得充满以下的输出:
I can reproduce that behaviour, and at the moment the video freezes my LogCat starts getting full with the following output:
16:25:25.239 14589-14601/my.app V/MediaPlayer? back from callback
16:25:25.499 14589-14686/my.app V/MediaPlayer? message received msg=7, ext1=0, ext2=0
16:25:25.499 14589-14686/my.app V/MediaPlayer? unrecognized message: (7, 0, 0)
16:25:25.499 14589-14686/my.app V/MediaPlayer? callback application
16:25:25.499 14589-14686/my.app V/MediaPlayer? back from callback
16:25:25.519 14589-14602/my.app V/MediaPlayer? message received msg=4, ext1=0, ext2=0
16:25:25.519 14589-14602/my.app V/MediaPlayer? Received seek complete
16:25:25.519 14589-14602/my.app V/MediaPlayer? All seeks complete - return to regularly scheduled program
16:25:25.519 14589-14602/my.app V/MediaPlayer? callback application
16:25:25.519 14589-14602/my.app V/MediaPlayer? back from callback
16:25:25.519 14589-14601/my.app V/MediaPlayer? message received msg=6, ext1=0, ext2=0
16:25:25.519 14589-14601/my.app V/MediaPlayer? Received MEDIA_STARTED
16:25:25.519 14589-14601/my.app V/MediaPlayer? callback application
16:25:25.519 14589-14601/my.app V/MediaPlayer? back from callback
16:25:25.789 14589-14686/my.app V/MediaPlayer? message received msg=7, ext1=0, ext2=0
16:25:25.789 14589-14686/my.app V/MediaPlayer? unrecognized message: (7, 0, 0)
16:25:25.789 14589-14686/my.app V/MediaPlayer? callback application
16:25:25.789 14589-14686/my.app V/MediaPlayer? back from callback
16:25:25.809 14589-14602/my.app V/MediaPlayer? message received msg=4, ext1=0, ext2=0
16:25:25.809 14589-14602/my.app V/MediaPlayer? Received seek complete
的code
以下(simplyfied)活动应该播放视频。 MediaPlayer.OnErrorListener()和MediaPlayer.OnInfoListener()将永远不会被调用。
The following (simplyfied) activity is supposed to play the video. MediaPlayer.OnErrorListener() and MediaPlayer.OnInfoListener() are never called.
public class VideoActivity extends Activity {
private MediaPlayer mediaPlayer;
private String videoPath = "some path obtained from the system";
// [...]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mediaPlayer = new MediaPlayer();
startMovie();
}
private void startMovie(){
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.setLooping(true);
mediaPlayer.setDataSource(videoPath);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
mp.start();
mp.seekTo(0);
}
});
mediaPlayer.prepare();
}
}
视频可以与该活动的生命周期中不同的视频文件路径启动几次,这就是为什么我停下来,开始在电影之前播放器复位。
The video can be started several times with a different video file path during the lifetime of the activity, that's why I stop and reset the player before starting the movie.
到目前为止,我在互联网上发现的唯一解决办法是,以确保在MediaPlayer不会被GC回收(我通过不使它的方法,本地对象一样),并实现了激活锁定,这也是我做了没有效果
So far the only solutions I found on the internet were to make sure the MediaPlayer is not collected by the GC (which I do by not making it a method-local object) and implement the WakeLock, which I also did without effect.
任何人都可以请帮我在这里和点我在正确的方向?谢谢!
Can anyone please help me here and point me in the right direction? Thank you!
推荐答案
更多的是解决办法不是解决办法,我最终的不的循环使用视频的 setLooping
的MediaPlayer
的方法。相反,我现在重新启动在的MediaPlayer
的 OnCompletion
回调的视频。经过大量的努力,这是唯一的方法我得到它跨越我测试所有设备上工作。
More a workaround than a solution, I ended up not looping the video using the setLooping
method of MediaPlayer
. Instead I am now restarting the video in the OnCompletion
callback of MediaPlayer
. After a lot of trying this was the only way I got it to work across all devices I am testing on.
public class VideoActivity extends Activity {
private MediaPlayer mediaPlayer;
private String videoPath = "some path obtained from the system";
// [...]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mediaPlayer = new MediaPlayer();
startMovie();
}
private void startMovie(){
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.setDataSource(videoPath);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
mp.start();
mp.seekTo(0);
}
});
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
startMovie();
}
});
mediaPlayer.prepare();
}
}
不过,如果有人对这个问题的有效解决方案,我会很乐意为纪念相应的答案是正确的。
Still, if someone has a valid solution to that problem I will be happy to mark the corresponding answer as correct.
这篇关于MediaPlayer的冻结而不是在Android 4.4的循环视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!