Android播放url视频问题
我有 .mp4 文件。如果我把它放在存储卡中,android默认的视频播放器可以正常播放。但是,如果我将其上传到网络服务器并尝试通过 Android 的网络浏览器播放它,它会显示“抱歉,该视频对于连接到此设备无效”。
同样的情况也发生了,我想通过我的应用程序来玩它。我使用了以下代码:
private SurfaceHolder holder;
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource("http://www.languagehostess.com/videos/aka1.mp4");
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
它给出了以下错误:
Command PLAYER_INIT completed with an error or info PVMFFailure
与该视频或代码相关的问题是什么?
I have .mp4 file. If I placed it in the memory card, android's default video player can play it normally. But If I upload it to the web server and try to play it through the web browser of Android, it is giving mag saying, "Sorry, the video is not valid for seaming to this device."
The same is happening is I want to play it through my App. I used the following code:
private SurfaceHolder holder;
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource("http://www.languagehostess.com/videos/aka1.mp4");
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
It is giving the follwing error:
Command PLAYER_INIT completed with an error or info PVMFFailure
What is the problem related the that video or code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要检查 Android 视频编码建议 。确保您的视频使用支持的代码进行编码,并且您的视频符合分辨率。我遇到了完全相同的问题,在视频正确编码后,流媒体就可以工作了。
另外,如果您还没有注意到,通常模拟器不会播放它们,您必须在真实设备上进行测试。
You need to check the Android Video Encoding Recommandations . Make sure that your video is encoded with the supported code, and your video respects the resolutions. I had the exact same issues and after the video were properly encoded the streamming worked.
Also if you didn't noticed yet, usually the emulator does not play them, and you'll have to test on a real device.