android – VideoView不仅仅在Galaxy s4上循环播放视频
作者:互联网
在我的应用程序中,我使用VideoView来传输视频文件,然后使用MediaPlayer.setLooping(true)制作VideoView循环视频.
这是一些代码 –
videoView.setVideoPath(url);
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (shouldLoopVideo) {
mp.setLooping(true);
}
videoView.start();
}
});
这段代码适用于所有设备,但Galaxy s4 android 4.2.2我在很多设备和许多Android版本上测试过,但唯一失败的是galaxy s4.
设备将播放视频一次,并停止(调用onCompletion侦听器后).
解决方法:
这是Android 4.4.2的错误.
我的解决方法:
private String mVideoPath;
private VideoView mVideoView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mVideoPath = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.backvideo;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mVideoView = (VideoView) view.findViewById(R.id.videoBackground);
mVideoView.setVideoURI(Uri.parse(mVideoPath));
mVideoView.setKeepScreenOn(true);
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
@Override
public void onCompletion(MediaPlayer mp) {
mVideoView.setVideoURI(Uri.parse(mVideoPath));
mVideoView.start();
}
});
mVideoView.start();
}
@Override
public void onPause() {
super.onPause();
mVideoView.pause();
}
@Override
public void onResume() {
super.onResume();
mVideoView.setVideoURI(Uri.parse(mVideoPath));
mVideoView.start();
}
标签:android,media-player,videoview,galaxy,android-videoview 来源: https://codeday.me/bug/20190703/1365758.html