使用媒体播放器播放视频时 SurfaceView 为空白
这是我的代码,但是当我启动媒体播放器时,它只发出声音,而表面没有显示任何内容。为什么?
我对此不知道。您有一些代码可以帮助我学习这个吗?
videoV = (SurfaceView) findViewById(R.id.SurfaceView1);
sh = videoV.getHolder();
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "sample2.mp4");
sh.addCallback(this);
mp = new MediaPlayer();
mp.setDataSource(file.getAbsolutePath());
mp.setDisplay(sh);
mp.prepare();
mp.start();
This is My code but when I start the mediaplayer it have only the sound come out and the surface have nothing shown . Why?
I have no idea on this. Do you have some code help me to learn with this.
videoV = (SurfaceView) findViewById(R.id.SurfaceView1);
sh = videoV.getHolder();
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "sample2.mp4");
sh.addCallback(this);
mp = new MediaPlayer();
mp.setDataSource(file.getAbsolutePath());
mp.setDisplay(sh);
mp.prepare();
mp.start();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试在
这
之后添加就我而言这很有帮助。
Try to add after
this
In my case it was helpful.
您添加了准备好的监听器吗?我在该方法中实现了开始,因为它是指示视频何时准备好渲染的触发器。
Have you added the on prepared listener? I implemented the start in that method since it is the trigger that indicates when the video is ready to be rendered.
试试这个代码。
resource
是您要播放的文件名,one.two
是包名称,您的路径可能类似于android.resource://package_name/raw/file_name< /code>
另请查看此教程
try this code.
resource
is file name which you want to play andone.two
is package name your path may as likeandroid.resource://package_name/raw/file_name
Also take a look at this tutorial
就我而言,在
OnCreate
方法中使用此代码片段帮助我找出哪些设备可以使用SurfaceView
找出
SurfaceView
和之间的差异>TextureView
请参阅此链接。In my case, using this snippet in
OnCreate
method helped me to find out which device can useSurfaceView
To find out differences between
SurfaceView
andTextureView
see this link.