Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a custom media player to play a custom codec in Android?

n00b here (first Android project). I have been given a custom video codec that has been integrated with an Android firmware build. It's an .so file containing a class that inherits from MediaPlayerInterface, as well as a custom MediaPlayerService implementation to return instances of the custom codec class from the create() factory function for the appropriate file types.

I want to use this codec as part of a video player application that can be installed on phones that do not contain the codec in firmware, by putting the .so file in my libs/armeabi folder and calling it via JNI.

From the answer to this question I gather that it is not possible to do this within the MediaPlayer framework, and I have to create a new media player from the ground up. To start with, I implemented a UI in Java, and set it up to use a custom view (instead of VideoView), which extends SurfaceView and used an instance of the MediaPlayer class to play videos. Then I replaced this instance of MediaPlayer with a custom media player Java class. I've set up the JNI interface, mimicking the way android_media_MediaPlayer.cpp does it, and calling the MediaPlayer C++ class in the JNI code. Now I need to replace that with a custom C++ media player class.

This is where I'm starting to run into problems. What is the recommended approach for implementing a custom player? Is there one? Is there some online documentation for any of this stuff besides trawling through the source? How much of the framework can I use and how much do I have to reimplement myself? Will I have to implement my own equivalent to MediaPlayerService?

Any tips greatly appreciated.

like image 595
samgak Avatar asked Apr 07 '11 09:04

samgak


People also ask

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.

Which media format is not supported by Android OS?

The AVI format is not supported on android devices. Most of the android users are looking for the easy way to play the AVI files on their android tablets and smartphones.


2 Answers

You can look up the source code of Android to get an idea about how Android have implemented the MediaPlayer interface in Java. You can follow on similar lines.

MediaPlayer Class Reference

like image 107
Eclipses Avatar answered Oct 05 '22 16:10

Eclipses


I hope your codec is not too CPU-intensive. The main reason Android supports only H.264 is (I guess) that there is hardware support for this codec in most devices. Other codecs will need to be processed by the CPU which will probably not be powerful enough.

like image 44
Guillaume Brunerie Avatar answered Oct 05 '22 16:10

Guillaume Brunerie