简体   繁体   English

Android 中的 MediaPlayer 和 VideoView 有什么区别

[英]What is the difference between MediaPlayer and VideoView in Android

I was wondering if there's a difference between them when it comes to streaming videos.我想知道在流式传输视频方面它们之间是否存在差异。

I know VideoView can be used for streaming and what is Mediaplayer for?我知道VideoView可用于流式传输, Mediaplayer有什么用? As far as I know, MediaPlayer can do the same thing as VideoView right?据我所知, MediaPlayer可以和VideoView做同样的事情,对吗?

Can anyone give me the answer?谁能给我答案?

And if I want to stream video from the server by using RTSP to Android, which one should I start with?如果我想使用 RTSP 将视频从服务器流式传输到 Android,我应该从哪一个开始? VideoView or MediaPlayer ? VideoViewMediaPlayer

Any suggestion?有什么建议吗?

Was asking the same question and as I understood from what Mark (CommonsWare) advised on numerous threads here, VideoView is a wrapper (200 hundred lines of code) for MediaPlayer and SurfaceView to provide embedded controls.问了同样的问题,正如我从 Mark (CommonsWare) 在这里的众多线程上所建议的那样,VideoView 是 MediaPlayer 和 SurfaceView 的包装器(20000 行代码),用于提供嵌入式控件。

He also kindly shared some examples:他还亲切地分享了一些例子:

https://github.com/commonsguy/cw-advandroid/blob/master/Media/Video/src/com/commonsware/android/video/VideoDemo.java https://github.com/commonsguy/cw-advandroid/blob/master/Media/Video/src/com/commonsware/android/video/VideoDemo.java

https://github.com/commonsguy/vidtry/blob/master/src/com/commonsware/android/vidtry/Player.java https://github.com/commonsguy/vidtry/blob/master/src/com/commonsware/android/vidtry/Player.java

and example from android sdk http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo.html和来自 android sdk 的示例http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo.html

Also some people had issues playing video on emulator, so make sure to test it on actual device if you have issues还有一些人在模拟器上播放视频时遇到问题,所以如果你有问题,请务必在实际设备上进行测试

VideoView is essentially a View that is tied to a MediaPlayer to make it a lot easier to implement videos in your app. VideoView 本质上是一个绑定到 MediaPlayer 的视图,可以更轻松地在您的应用中实现视频。 If you aren't doing much custom work, VideoView is the way to go.如果您不做太多自定义工作,那么 VideoView 是您的最佳选择。

That said, you can also pass the RTSP link off to the system to use the most appropriate app for playing the video, which is even easier to do:也就是说,您还可以将 RTSP 链接传递给系统以使用最合适的应用程序来播放视频,这更容易做到:

String url = "rtsp://yourrtsplink.com/blah";
Uri uri = Uri.parse(url);
startActivity(new Intent(Intent.ACTION_VIEW, uri));

Video should be tested on a device, since emulator playback is poor, and you should also be aware that RTSP requires an extra port to be open, which is blocked by some firewalls.视频应该在设备上测试,因为模拟器播放效果很差,而且您还应该知道 RTSP 需要打开一个额外的端口,该端口被某些防火墙阻止。

VideoAdView 是 MediaPlayer 和 SurfaceView 的包装器,使用 VideoView 实现视频播放器比使用 MediaPlayer 更容易,如果视频文件存储在应用程序的内部存储中,请使用内容提供程序或将它们存储为世界可读,否则将不工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM