【发布时间】:2017-06-07 07:36:36
【问题描述】:
我看过很多教程,但有些地方出了问题。我有简单的 mainactivity,并且它的布局上有一个 VideoView。我从 youtube 下载了一个视频,因为 .mp4 文件大小约为 10 mb。我在 youtube 上找到了一个很棒的关于 videoview 的示例,如下链接所示。
https://www.youtube.com/watch?v=tPeDn18FrGY&t=75s
公共类 MainActivity 扩展 AppCompatActivity {
private VideoView bgVideo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bgVideo=(VideoView) findViewById(R.id.bg_videoview);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.bgvideo);
bgVideo.setVideoURI(uri);
bgVideo.start();
bgVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
}
}
我使用 genymotion 模拟器。当我运行应用程序时,出现“无法播放”错误。在 android 监视器上是这样的。
06-07 03:16:28.675 2146-2146/com.sample E/MediaPlayer: Error (1,-2147483648)
06-07 03:16:28.675 2146-2146/com.sample D/VideoView: Error: 1,-2147483648
06-07 03:16:28.692 2146-2146/com.sample E/MediaPlayer: Error (1,-2147483648)
06-07 03:16:28.692 2146-2146/com.sample D/VideoView: Error: 1,-2147483648
06-07 03:16:28.709 2146-2146/com.sample E/MediaPlayer: Error (1,-2147483648)
06-07 03:16:28.709 2146-2146/com.sample D/VideoView: Error: 1,-2147483648
06-07 03:16:28.742 2146-2146/com.sample E/MediaPlayer: Error (1,-32)
06-07 03:16:28.742 2146-2146/com.sample D/VideoView: Error: 1,-32
06-07 03:16:28.758 2146-2146/com.sample E/MediaPlayer: Error (1,-38)
06-07 03:16:28.758 2146-2146/com.sample D/VideoView: Error: 1,-38
06-07 03:16:29.526 2146-2146/com.sample I/Choreographer: Skipped 44 frames! The application may be doing too much work on its main thread.
我该如何解决?
【问题讨论】:
-
检查this answer。
-
尝试在设备而不是模拟器上运行