Android 使用 MediaPlayer 流式传输视频
我又回来了,还有一个问题!
我正在尝试创建一个应用程序来列出来自 Own3d.TV、Justin.Tv 等的选定直播流...
如果我的研究没有完全失败,我可以使用 MediaPlayer 对象来流视频,唯一的问题是我该如何使用它?
到目前为止,我的代码看起来像这样,但在尝试准备 MediaPlayer 时它给了我一个异常。
public class Media extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SurfaceView sw = new SurfaceView(this);
SurfaceHolder sh = sw.getHolder();
setContentView(sw);
Uri ur = Uri.parse("http://www.twitch.tv/widgets/live_embed_player.swf?channel=hashe");
MediaPlayer mp = new MediaPlayer();
mp.setDisplay(sh);
try {
mp.setDataSource("http://www.twitch.tv/widgets/live_embed_player.swf?channel=hashe");
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
//mp.setDisplay(sw);
}
}
是否可以使用 MediaPlayer 从这些网站流式传输视频?
如果不是,我应该如何解决这个问题?
谢谢!
I'm back with another problem!
I'm trying to create an app that would list a selected Livestreams, from Own3d.TV, Justin.Tv etc...
If my research isn't totally failed, I can use the MediaPlayer object to Stream video, the only question is how do I use it?
So far my code looks like this, but it's giving me an Exception when trying to prepare the MediaPlayer.
public class Media extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SurfaceView sw = new SurfaceView(this);
SurfaceHolder sh = sw.getHolder();
setContentView(sw);
Uri ur = Uri.parse("http://www.twitch.tv/widgets/live_embed_player.swf?channel=hashe");
MediaPlayer mp = new MediaPlayer();
mp.setDisplay(sh);
try {
mp.setDataSource("http://www.twitch.tv/widgets/live_embed_player.swf?channel=hashe");
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
//mp.setDisplay(sw);
}
}
Is it even possible to Stream the video from these sites using the MediaPlayer?
If not, how shoud I approach this problem?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现 mediaPlayer 时,尝试这样的方法,它对我来说效果很好: http://android-er.blogspot.com/2010/11/play-3gp-video-file-using-mediaplayer.html
但我认为,你不能像你在代码中编写的那样使用源代码。您必须使用直接通过渐进式流传输视频的某个 URL,而不是嵌入播放器的 html 站点的 URL。您可以认识到:当您在互联网浏览器中编写带有流媒体视频的有用 URL 时,浏览器开始将该流媒体视频下载到您的计算机中。我认为,MediaPlayer 仅支持核心 .3gp 或 .mp4 格式。
我希望你能理解我糟糕的英语
when implementing mediaPlayer, try something like this, it worked fine for me: http://android-er.blogspot.com/2010/11/play-3gp-video-file-using-mediaplayer.html
but I think, u cant use source like u have written in your code. You have to use some URL from where is video streamed directly with progresive streaming, not URL of html site with player embeded. You can recognize: when u write useful URL with streamed video in your internet browser, browser starts to download this streamed video in your computer. And I think, MediaPlayer supports in core .3gp or .mp4 format only..
I hope u understand my bad english
使用
ExoPlayer
而不是MediaPlayer
。参见Android官方文档:ExoPlayer - Android 开发者
Use
ExoPlayer
instead ofMediaPlayer
. See Android official documentation:ExoPlayer - Android Developers