Lazy Ninja
Lazy Ninja

Reputation: 22527

Custom MediaPlayer class in 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.

Upvotes: 7

Views: 2329

Answers (3)

Will Shaw
Will Shaw

Reputation: 52

This may not help but you can I know for music players you just create java class, and create your mediaplayer, name public your name extends mediaplayer. Refer to Vanilla music github, search for vanilla music player and copy class to your app and Change a few things like requesting audio effects, for equaliser I put custom stuff in onprepared for my class, and incompletetion listener, then simply change the Mediaplayer player = new Mediaplayer, with For e.g. my name I used from vanilla mediaplayer so then say VanillaMediaplayer player or variable = new VanillaMediaplayer it helps also do less work, then use as you wish, hope this helps.

Upvotes: 1

RonTLV
RonTLV

Reputation: 2556

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

Upvotes: 1

frijj2k
frijj2k

Reputation: 171

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

Upvotes: 1

Related Questions