h6ah4i / android-openslmediaplayer

Re-implementation of Android's MediaPlayer and audio effect classes based on OpenSL ES APIs.
https://openslmediaplayer.h6ah4i.com
Apache License 2.0
418 stars 97 forks source link

Pause/resume works slowly #41

Open anonym24 opened 7 years ago

anonym24 commented 7 years ago

Pause/resume working not instantly when I press pause/resume button. So for example it has a little delay before it pauses after I pressed my pause button. No such delay with default Android MediaPlayer, also apps like PowerAmp, AIMP don't have this problem.

I already use this solution to disable smooth fading, but this is quite another problem when it just works not fast as wanted

    factory = new OpenSLMediaPlayerFactory(activity.getApplicationContext()) {

            @Override
            protected int getMediaPlayerOptions () {
                return 0;
            }

        };
h6ah4i commented 7 years ago

@anonym24 Hi. Thank you for the issue report.

I have tweaked some parameters and try the following branch code 😉

anonym24 commented 7 years ago

Yeah I see the difference (I compiled one project with current library and one with library from feature/improve_play_pause_response)

In previous library the biggest delay before pause had HybridMediaPlayerFactory (OpenSLMediaPlayerFactory was faster). Now I see that with the latest modified library it became much better (Standard MediaPlayer still has the fastest response)

switch (type) {
            case MediaPlayerStateStore.PLAYER_IMPL_TYPE_STANDARD:
                mFactory = new StandardMediaPlayerFactory(mContext);
                break;
            case MediaPlayerStateStore.PLAYER_IMPL_TYPE_OPENSL:
                mFactory = new OpenSLMediaPlayerFactory(mContext) {

                    @Override
                    protected int getMediaPlayerOptions () {
                        return 0;
                    }

                };
                break;
            case MediaPlayerStateStore.PLAYER_IMPL_TYPE_HYBRID:
                //mFactory = new HybridMediaPlayerFactory(mContext);
                mFactory = new HybridMediaPlayerFactory(mContext) {

                    @Override
                    protected int getMediaPlayerOptions () {
                        return 0;
                    }

                };
                break;
        }

Thanks!

anonym24 commented 7 years ago

Are you going to push this change to new version?