14

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.

Community
  • 1
  • 1
samgak
  • 23,944
  • 4
  • 60
  • 82

3 Answers3

2

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

beryllium
  • 29,669
  • 15
  • 106
  • 125
Eclipses
  • 1,008
  • 1
  • 9
  • 17
  • 3
    Thanks for your reply. I read through the Android source code for the MediaPlayer interface before posting the initial question. Following on similar lines doesn't seem possible. Specifically, the built-in MediaPlayer uses the ACCESS_SURFACE_FLINGER permission, which seems to be denied to apps that aren't built-in. I want users to be able to download and install my player, not receive it pre-installed on the phone. – samgak Jul 11 '11 at 02:36
  • 1
    Hi, please share your latest findings on how to implement custom codec for android. @samgak – Hosein Hamedi Mar 09 '16 at 06:45
2

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.

Guillaume Brunerie
  • 4,676
  • 3
  • 24
  • 32
1

why don't you use VLC instead? you can get the source code, supports every format. trim it down for your purpose, skin it, voila, c'est fini. i know they're actually hacking on the code now, you could jump it and help them out.

http://gigaom.com/video/vlc-for-android-demo-beta/

  • 4
    VLC is published under the GPLv2 license. You can not use the code in your own commercial projects. – philipp Aug 01 '13 at 22:17