Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom MediaPlayer class in android

Tags:

java

android

I have just finished a project where I use a webwiew for video playback. Now I am asked to replace the webview part with a custom player. The player should be capable to handle HLS.

If I use VideoView and MediaController, I can play live stream. But unfortunately, the MediaController has its own controls. I want my own controls and thats where I am stuck.

So far I tried:

  1. To write the MediaController class all over again and try to change the layout. It didnt work because I could not clear all the errors due to the dependencies.
  2. I tried using vidtry code (http://github.com/commonsguy/vidtry) for reference but no luck.
  3. I tried to build a class that extends MediaController but that didnt work either.

I have been in almost every thread on Stackoverflow regarding custom media player but couldnt find information to get me started.
Is it possible to create a custom media player class without using NDK?
If someone knows how to create a custom media player class, please help me.

like image 667
Lazy Ninja Avatar asked Aug 29 '12 09:08

Lazy Ninja


People also ask

What is the MediaPlayer class?

MediaPlayer. This class is the primary API for playing sound and video. AudioManager. This class manages audio sources and audio output on a device.

What is MediaPlayer release?

android.media.MediaPlayer. MediaPlayer class can be used to control playback of audio/video files and streams.


2 Answers

You could use VideoView on it's own and call it's methods to control playback such as start(), stopPlayback(), pause(), resume(), seekTo() etc. (See class reference here: http://developer.android.com/reference/android/widget/VideoView.html)

Just create your on-screen controls however you want (buttons/images) and bind your playback control code code to their events.

You will also want to disable the inbuilt VideoView controls by removing the touchable property in the layout.xml...

<VideoView 
    android:id="@+id/myVideoView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:clickable="false" >
like image 108
frijj2k Avatar answered Oct 02 '22 06:10

frijj2k


I recommend using VLC as it support nearly all video formats, and of-course streaming. You can try to pick up on a pre-compiled libvlc AAR file from github or compile VLC by yourself: AndroidCompile.

Example of pre-compiled libvlc you can find here: https://github.com/mrmaffen/vlc-android-sdk

This is not the latest version by I believe it will be good for your needs. Next you will will need to create the code around the library. Example: https://github.com/Ivshti/libvlc-android-sample

like image 20
RonTLV Avatar answered Oct 02 '22 05:10

RonTLV