Search code examples
androidandroid-mediaplayerandroid-source

Calling MediapPlayer Invoke method from the application


I am trying to implement extra functionalities to the Aosp Mediaplayer (like setspeed in awesomeplayer).

I see in the AOSP code that there is an API called Invoke in mediaplayer.java public void invoke(Parcel request, Parcel reply) and it traverse till AwesomePlayer.cpp filestatus_t AwesomePlayer::invoke(const Parcel &request, Parcel *reply).

I thought of using this Invoke method from application to call AwesomePlayer's invoke API and from there, a call to my setspeed method, so that I don't need to modify the android.jar file.

But, I couldn't use this invoke API from the application. I don't see any word mentioned about invoke API in http://developer.android.com/reference/android/media/MediaPlayer.html

Can somebody help me in using this invoke API from application.


Solution

  • The invoke method is hidden, which is why you can't access it in a normal manner. You can probably get at it through reflection though. I.e. something like this:

    Class mediaPlayerClass = Class.forName("android.media.MediaPlayer");
    Method mediaPlayerInvoke = mediaPlayerClass.getMethod("invoke", new Class[]{Parcel.class, Parcel.class});
    mediaPlayerInvoke.invoke(parcel1, parcel2);
    

    Note that this way of doing things isn't recommended, as hidden methods can be subject to change or removal which could make your app break if you rely on them.