Android MediaPlayer不能在Android 5.1.1上玩Galaxy S6

我看到一个特定于运行Android 5.1.1的Galaxy S6的问题。 我正在使用MediaPlayer播放audiostream,在设备和Android版本的此特定configuration上,它无法达到onPrepared方法,因此从不播放。

@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(); } } 

只是重复,它适用于所有其他设备和Android版本。

以下是从控制台输出:

  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 

Solutions Collecting From Web of "Android MediaPlayer不能在Android 5.1.1上玩Galaxy S6"

这是一个部分的解决scheme,但在我看来,这是最常见的解决scheme 。 MediaPlayer很早以前就已经创build好了,因此我们不需要它那么灵活。 我从现在开始使用Exoplayer ,最后一个版本只有audio播放。 所以我猜如果你改变你的audio播放器的实现使用Exoplayer它将解决大多数问题和后来的问题。

Exoplayer是来自Google开发者的强大的玩家,可作为外部库pipe理员使用,因此您不必在某些Android版本上pipe理错误的执行。

Exoplayer GitHub
Exoplayer开发者指南