Android MediaPlayer - setPlaybackParams throws a security exception

1.7k views Asked by At

I'm trying to play a video faster/slower via the following block of code.

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            socket.send(positionID + ":playState:ready:empty");
            player = mp;
            player.setPlaybackParams(new PlaybackParams().setSpeed(1.0f));
        }
    });

I'm passing '1' as the parameter at the moment just for testing, which is supposed to be normal playback speed. But I get the following error regardless of what number I pass.

01-04 18:49:17.308 24548-24548/com.spectiv.slave E/AndroidRuntime: FATAL EXCEPTION: main
                                                               Process: com.spectiv.slave, PID: 24548
                                                               java.lang.SecurityException
                                                                   at android.media.MediaPlayer.setPlaybackParams(Native Method)
                                                                   at com.spectiv.slave.videoActivity$3.onPrepared(videoActivity.java:80)
                                                                   at android.widget.VideoView$2.onPrepared(VideoView.java:432)
                                                                   at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2830)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                   at android.os.Looper.loop(Looper.java:148)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I'm working targeting API level 23 with a compiled SDK version of 24 and I'm running the application on an Odroid C2. Any help is greatly appreciated.


EDIT - This error doesn't happen on an emulator. I have no idea what's different about the Android running on this Odroid C2. They were both Marshmallow.

4

There are 4 answers

2
Euroclydon37 On BEST ANSWER

Just wanted to put this as an answer for anyone searching. The error only happens on this specific piece of hardware (Odroid C2). Running the code in an emulator works.

1
petrumo On

I would try with

player.setPlaybackParams(player.getPlaybackParams().setSpeed(1.0f))

assuming that the video is playing without setting the playback params

0
Mateusz Biedron On

I got the same problem on C2. Try release media player onDestroyView() function of your fragment. or release media player quicker than that.

It appears because pervious media player is not correctly released.

0
Yahya M On

You have not started the Media Player..

player = mp;
 player .start()
        player.setPlaybackParams(new PlaybackParams().setSpeed(1.0f));