Android MediaPlayer 无法在 Android 5.1.1 的 Galaxy S6 上播放
Android MediaPlayer not playing on Galaxy S6 with Android 5.1.1
我发现了一个特定于 Galaxy S6 运行 Android 5.1.1 的问题。我正在使用 MediaPlayer 播放音频流,在这种特定的设备配置和 Android 版本上,它无法到达 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
这是一个部分解决方案,但在我看来它是最有效的解决方案。 MediaPlayer 是很久以前创建的,因此不是我们想要的那样灵活。我从现在开始使用 Exoplayer 一年了,最后一个版本只提供音频播放。所以我想如果你改变你的音频播放器的实现来使用 Exoplayer 它会解决大部分问题和以后的问题。
Exoplayer 是来自 google 开发人员的强大播放器,可作为外部库使用,因此您不必在某些 Android 版本上管理错误的实现。
我发现了一个特定于 Galaxy S6 运行 Android 5.1.1 的问题。我正在使用 MediaPlayer 播放音频流,在这种特定的设备配置和 Android 版本上,它无法到达 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
这是一个部分解决方案,但在我看来它是最有效的解决方案。 MediaPlayer 是很久以前创建的,因此不是我们想要的那样灵活。我从现在开始使用 Exoplayer 一年了,最后一个版本只提供音频播放。所以我想如果你改变你的音频播放器的实现来使用 Exoplayer 它会解决大部分问题和以后的问题。
Exoplayer 是来自 google 开发人员的强大播放器,可作为外部库使用,因此您不必在某些 Android 版本上管理错误的实现。