使用 MediaPlayer 在 Android 上未显示视频流(MPEG4 视频)?
有一个在线流,大小为 512Kb MPEG4,在线总大小为 312mb,如果我在查看文档后正确地播放电影,我只是简单地说:
MediaPlayer mp = new MediaPlayer();
Try{
mp.setDataSource("http://site.com/movie.mp4");
}
Try {
mp.prepare();
}
mp.start();
按下按钮后几秒钟后触发播放按下按钮后它会播放音频但不显示视频,为什么不呢?我是否必须使用表面视图或其他东西来进行流的视觉播放(android 文档似乎对我没有多大帮助)?
There is an online stream that is 512Kb MPEG4 and total size of 312mb online and if I'm correct after looking over docs in order to play the movie I just simply put:
MediaPlayer mp = new MediaPlayer();
Try{
mp.setDataSource("http://site.com/movie.mp4");
}
Try {
mp.prepare();
}
mp.start();
It is triggered to play after a button press which after a few seconds after pressing the button it plays the audio BUT doesn't show the video, why not? Do I have to use a surface view or something for visual playback of the stream (the android docs don't seem to help me much)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,是的,您需要一个
SurfaceView
来使用MediaPlayer
播放视频。或者,使用VideoView
并跳过MediaPlayer
。其次,如果您尝试在模拟器中播放此内容,这是典型的行为。除非您拥有超快的硬件,否则视频播放将无法在模拟器上正常运行。我建议使用实际的 Android 设备来开发视频播放器。
First, yes, you need a
SurfaceView
to play back video with aMediaPlayer
. Or, use aVideoView
and skip theMediaPlayer
.Second, if you are trying to play this back in the emulator, this is typical behavior. Video playback will not work well on the emulator unless you have crazy-fast hardware. I recommend that video player development be done with actual Android devices.