问题
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.
回答1:
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
回答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.
回答3:
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/
来源:https://stackoverflow.com/questions/5578569/how-do-i-create-a-custom-media-player-to-play-a-custom-codec-in-android