我想在Videoview
中播放.mp4视频但不播放。生成错误"Sorry! video cannot be played"
。
public class MainActivity extends Activity {
VideoView videoview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoview=(VideoView)findViewById(R.id.video);
videoview.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.snowfall));
videoview.start();
}
任何帮助将不胜感激。谢谢!
答案 0 :(得分:2)
当框架尚未准备好播放视频时,会抛出此错误。您的videoview.start()
过早被调用。添加侦听器以在视频准备就绪时开始播放。
将videoview.start()
替换为:
videoview.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
videoview.start();
}
});
答案 1 :(得分:0)
此代码将正常工作...... !!
Uri uri= Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.video);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
//loop the video
videoview.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});