Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? As far as I know, MediaPlayer can do the same thing as VideoView right?

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? VideoView or MediaPlayer?

Any suggestion?

like image 734
oattie Avatar asked Nov 04 '10 11:11

oattie


People also ask

What is the use of MediaPlayer class?

MediaPlayer Class in Android is used to play media files. Those are Audio and Video files. It can also be used to play audio or video streams over the network.

How do I play audio files on Android?

Prepare media file: To play a media file, you need to first prepare it i.e. you need to load the file for playback. Methods used for doing this are prepare(), prepareAsync(), and setDataSource(). Start/Pause the playback: After loading the media file, you can start playing the media file by using the start() method.

What method is used to call media?

mediaPlayer. start(); mediaPlayer. pause(); On call to start() method, the music will start playing from the beginning.

How do I turn off Media Player on Android?

The feature is as simple as tapping and holding on the media card of any app then choosing Dismiss. Playback stops and the controls go away.


1 Answers

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.

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/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

Also some people had issues playing video on emulator, so make sure to test it on actual device if you have issues

like image 181
mishkin Avatar answered Sep 16 '22 11:09

mishkin