- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够添加我创建的视频,当它出现在屏幕上时会自动开始播放,目前我的代码如下所示:
VideoView videoview = (VideoView) findViewById(R.id.button10);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.group_project);
videoview.setVideoURI(uri);
videoview.start();
目前,当我点击并进入该屏幕时,没有任何反应。当我使用媒体播放器时它播放声音,但我真的想添加这个视频。任何帮助将不胜感激。
最佳答案
setOnPreparedListener()
方法的使用非常重要,并且确保在/raw
文件夹中有一个名为group_project.mp4
的视频。
final VideoView videoview = (VideoView) findViewById(R.id.button10);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.group_project);
videoview.setVideoURI(uri);
videoview.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
videoview.start();
}
});
阅读文档:
A MediaPlayer object must first enter the Prepared state before playback can be started. There are two ways (synchronous vs. asynchronous) that the Prepared state can be reached: either a call to prepare() (synchronous) which transfers the object to the Prepared state once the method call returns, or a call to prepareAsync() (asynchronous) which first transfers the object to the Preparing state after the call returns (which occurs almost right way) while the internal player engine continues working on the rest of preparation work until the preparation work completes. When the preparation completes or when prepare() call returns, the internal player engine then calls a user supplied callback method, onPrepared() of the OnPreparedListener interface, if an OnPreparedListener is registered beforehand via setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener).
关于java - 如何将视频文件 (mp4) 添加到我的 android 应用程序中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27281396/
我是一名优秀的程序员,十分优秀!