10

I'm seeing an issue that is specific to the Galaxy S6 running Android 5.1.1. I'm using MediaPlayer to play audio streams and on this specific configuration of device and Android version, it fails to ever reach the onPrepared method, and therefore never plays.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAndroidPlayer = new MediaPlayer();

        mAndroidPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
                System.out.print("ERROR " + i);
                return false;
            }
        });

        mAndroidPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                System.out.println("PREPARED");
                mAndroidPlayer.start();
            }
        });

        mAndroidPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

        try {
            mAndroidPlayer.setDataSource("http://live.radioart.com/fFilm_scores.mp3");
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            mAndroidPlayer.prepareAsync();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }

Just to re-iterate, it works fine on all other devices and Android versions.

Below is output from the console:

    09-04 09:54:51.112  24991-24991/com.tsm.mediaplayertest E/Zygote﹕ MountEmulatedStorage()
09-04 09:54:51.112  24991-24991/com.tsm.mediaplayertest E/Zygote﹕ v2
09-04 09:54:51.112  24991-24991/com.tsm.mediaplayertest I/libpersona﹕ KNOX_SDCARD checking this for 10229
09-04 09:54:51.112  24991-24991/com.tsm.mediaplayertest I/libpersona﹕ KNOX_SDCARD not a persona
09-04 09:54:51.112  24991-24991/com.tsm.mediaplayertest I/SELinux﹕ Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-G920V_5.1.1_0024
09-04 09:54:51.112  24991-24991/com.tsm.mediaplayertest E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
09-04 09:54:51.112  24991-24991/com.tsm.mediaplayertest I/art﹕ Late-enabling -Xcheck:jni
09-04 09:54:51.122  24991-24991/com.tsm.mediaplayertest D/TimaKeyStoreProvider﹕ TimaSignature is unavailable
09-04 09:54:51.122  24991-24991/com.tsm.mediaplayertest D/ActivityThread﹕ Added TimaKeyStore provider
09-04 09:54:51.132  24991-24998/com.tsm.mediaplayertest E/art﹕ Failed sending reply to debugger: Broken pipe
09-04 09:54:51.132  24991-24998/com.tsm.mediaplayertest I/art﹕ Debugger is no longer active
09-04 09:54:51.132  24991-24991/com.tsm.mediaplayertest I/InjectionManager﹕ Inside getClassLibPath + mLibMap{0=, 1=}
09-04 09:54:51.132  24991-24991/com.tsm.mediaplayertest I/InjectionManager﹕ Inside getClassLibPath caller
09-04 09:54:51.142  24991-24991/com.tsm.mediaplayertest D/InjectionManager﹕ InjectionManager
09-04 09:54:51.142  24991-24991/com.tsm.mediaplayertest D/InjectionManager﹕ fillFeatureStoreMap com.tsm.mediaplayertest
09-04 09:54:51.142  24991-24991/com.tsm.mediaplayertest I/InjectionManager﹕ Constructor com.tsm.mediaplayertest, Feature store :{}
09-04 09:54:51.142  24991-24991/com.tsm.mediaplayertest I/InjectionManager﹕ featureStore :{}
09-04 09:54:51.162  24991-24991/com.tsm.mediaplayertest D/SecWifiDisplayUtil﹕ Metadata value : SecSettings2
09-04 09:54:51.172  24991-24991/com.tsm.mediaplayertest D/PhoneWindow﹕ *FMB* installDecor mIsFloating : false
09-04 09:54:51.182  24991-24991/com.tsm.mediaplayertest D/PhoneWindow﹕ *FMB* installDecor flags : -2139029248
09-04 09:54:51.202  24991-24991/com.tsm.mediaplayertest I/MediaPlayer﹕ Need to enable context aware info
09-04 09:54:51.202  24991-24991/com.tsm.mediaplayertest V/MediaPlayer-JNI﹕ native_setup
09-04 09:54:51.202  24991-24991/com.tsm.mediaplayertest V/MediaPlayer﹕ constructor
09-04 09:54:51.202  24991-24991/com.tsm.mediaplayertest V/MediaPlayer﹕ setListener
09-04 09:54:51.202  24991-24991/com.tsm.mediaplayertest V/MediaPlayer-JNI﹕ setAudioStreamType: 3
09-04 09:54:51.202  24991-24991/com.tsm.mediaplayertest V/MediaPlayer﹕ MediaPlayer::setAudioStreamType
09-04 09:54:51.212  24991-24991/com.tsm.mediaplayertest V/MediaPlayer﹕ setVideoSurfaceTexture
09-04 09:54:51.212  24991-24991/com.tsm.mediaplayertest V/MediaPlayer﹕ prepareAsync
09-04 09:54:51.212  24991-24991/com.tsm.mediaplayertest D/Activity﹕ performCreate Call Injection manager
09-04 09:54:51.212  24991-25004/com.tsm.mediaplayertest D/MediaHTTPConnection﹕ setReadTimeOut =  30000ms
09-04 09:54:51.212  24991-24991/com.tsm.mediaplayertest I/InjectionManager﹕ dispatchOnViewCreated > Target : com.tsm.mediaplayertest.MainActivity isFragment :false
09-04 09:54:51.212  24991-25010/com.tsm.mediaplayertest D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
09-04 09:54:51.222  24991-25004/com.tsm.mediaplayertest D/MediaHTTPConnection﹕ setReadTimeout with 30000ms
09-04 09:54:51.222  24991-25004/com.tsm.mediaplayertest I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
09-04 09:54:51.222  24991-25004/com.tsm.mediaplayertest I/System.out﹕ (HTTPLog)-Static: isShipBuild true
09-04 09:54:51.222  24991-25004/com.tsm.mediaplayertest I/System.out﹕ (HTTPLog)-Thread-5351-996493763: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
09-04 09:54:51.222  24991-25004/com.tsm.mediaplayertest I/System.out﹕ (HTTPLog)-Thread-5351-996493763: SMARTBONDING_FEATURE_ENABLED is true
09-04 09:54:51.222  24991-25004/com.tsm.mediaplayertest I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
09-04 09:54:51.222  24991-25004/com.tsm.mediaplayertest I/System.out﹕ KnoxVpnUidStorageknoxVpnSupported API value returned is false
09-04 09:54:51.222  24991-24991/com.tsm.mediaplayertest D/PhoneWindow﹕ *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
09-04 09:54:51.222  24991-24991/com.tsm.mediaplayertest D/PhoneWindow﹕ *FMB* isFloatingMenuEnabled return false
09-04 09:54:51.242  24991-24991/com.tsm.mediaplayertest D/SRIB_DCS﹕ log_dcs ThreadedRenderer::initialize entered!
09-04 09:54:51.262  24991-25010/com.tsm.mediaplayertest D/libEGL﹕ loaded /vendor/lib/egl/libGLES_mali.so
09-04 09:54:51.272  24991-25010/com.tsm.mediaplayertest I/OpenGLRenderer﹕ Initialized EGL, version 1.4
09-04 09:54:51.282  24991-25010/com.tsm.mediaplayertest I/OpenGLRenderer﹕ HWUI protection enabled for context ,  &this =0xf4d8c940 ,&mEglDisplay = 1 , &mEglConfig = -185126244
09-04 09:54:51.282  24991-25010/com.tsm.mediaplayertest D/OpenGLRenderer﹕ Get maximum texture size. GL_MAX_TEXTURE_SIZE is 8192
09-04 09:54:51.282  24991-25010/com.tsm.mediaplayertest D/OpenGLRenderer﹕ Enabling debug mode 0
09-04 09:54:51.282  24991-25010/com.tsm.mediaplayertest D/mali_winsys﹕ new_window_surface returns 0x3000,  [1440x2560]-format:1
09-04 09:54:51.292  24991-24991/com.tsm.mediaplayertest I/InjectionManager﹕ dispatchCreateOptionsMenu :com.tsm.mediaplayertest.MainActivity
09-04 09:54:51.292  24991-24991/com.tsm.mediaplayertest I/InjectionManager﹕ dispatchPrepareOptionsMenu :com.tsm.mediaplayertest.MainActivity
09-04 09:54:51.322  24991-24991/com.tsm.mediaplayertest I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@356f9c4b time:29488057
09-04 09:54:51.672  24991-25004/com.tsm.mediaplayertest I/MediaHTTPConnection﹕ response code = 200
09-04 09:54:51.672  24991-25004/com.tsm.mediaplayertest V/MediaHTTPConnection﹕ mTotalSize is -1
09-04 09:54:51.672  24991-25004/com.tsm.mediaplayertest D/MediaHTTPConnection﹕ getProperties 16
09-04 09:54:51.672  24991-25013/com.tsm.mediaplayertest D/MediaHTTPConnection﹕ getProperties 16
09-04 09:54:52.142  24991-24998/com.tsm.mediaplayertest I/art﹕ Ignoring second debugger -- accepting and dropping
codeman
  • 8,868
  • 13
  • 50
  • 79
  • TBH, I have no idea why is this happening. Back in time, samsung devices had bug that did not called `onPrepareListener `on `VideoView`. If this happens only on S6, you could exclude adding this listener and call `.start() ` when buffering is over some threshold (could be 100%) inside `OnBufferingUpdateListener` since you are streaming from URI. – Nikola Despotoski Sep 06 '15 at 00:34
  • onBufferingUpdateListener also never gets called. – codeman Sep 06 '15 at 01:04
  • That complicates things to a newer level. Start separate thread/asyntask that will check the buffering percentage or start recursive handler, but be careful. – Nikola Despotoski Sep 06 '15 at 01:18
  • updated with output from console. – codeman Sep 07 '15 at 23:09
  • yes, works on other devices with android 5.1.1 (including nexus 5). – codeman Sep 08 '15 at 17:45
  • is there maybe some way i could download the mediaplayer source for android and point my project to use that instead of samsung's android? – codeman Sep 09 '15 at 14:28
  • I had a strange problem similar to this. Check out this. Don't know if it helps. http://stackoverflow.com/questions/30481871/android-spinner-not-working-on-samsung-devices-with-android-5-0 – Raimundo Sep 09 '15 at 14:40
  • Just so you don't feel alone, I believe I'm encountering the same problem. – Matt Harrington Oct 17 '15 at 22:31
  • I have the same issue. For certain online streams the .prepare() never returns. And none of the callbacks (including onErrorListener) are ever called. Same for .prepareAsync(). My code works fine on S3, S4, and S5, but not S6 :( – Ken Roy Oct 19 '15 at 20:13
  • After more testing I discovered the following: 1. Turn off Wifi and use only Cell network 2. Start http stream that won't play 3. Turn Wifi on while app stuck waiting on prepare() or prepareAsync() a few moments later the stream plays. So I can get the stream to play, but only after causing a network change event from Wifi to Cell. It does not work in the opposite direction. – Ken Roy Oct 23 '15 at 00:59
  • 1
    This is really frustrating. I've had an app out in the wild for about a year now and it works fine. Now I have to consider changing my entire implementation because Samsung can't get their sh** together? (Granted, I'm a better developer now than I was then, and could have made it easier on myself....) – AutonomousApps Nov 22 '15 at 23:08

1 Answers1

7

It's a partial solution but to my mind it's the most perenne solution. MediaPlayer has been created a long time ago, and therefore is not very flexibile as we want it. I have been using Exoplayer from one year now and last version come with audio playback only. So I guess if you change your implementation of your audio player to use Exoplayer it will solve most issue and later issue.

Exoplayer is a powerfull player from google developers, available as an external librarie so you don't have to manage buggy implementation on some Android version.

Exoplayer GitHub
Exoplayer developer guide

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119
  • I encountered the same problem with the S6 as the OP, and ExoPlayer fixed it. – Matt Harrington Oct 27 '15 at 19:56
  • I don't think this is a valid solution. It suggest to use something completely else and does not provide a concrete solution to the problem at hand. It's arguing that the framework is "old" and could not be used. Comments? – anthonymonori Nov 23 '16 at 14:53
  • @anthonymonori you're right, it's not a proper solution but we've come to a point where Google use Exoplayer in Youtube for example. For me, we have some issue with the codecs on each vendors, and some issues on MediaPlayer. This solution provide an answer to fix issues related to MediaPlayer by using a different standalone player. – Hugo Gresse Nov 23 '16 at 16:02