Android 4.0.4 MediaPlayer prepare issue using RTSP urls

倾然丶 夕夏残阳落幕 提交于 2019-12-04 03:45:02

Use mp.prepareAsync() as it is better for streaming media. Using prepare() blocks until MediaPlayer is ready for playback or an IllegalStateException occurs. Also, in android 4 (ICS), blocking on any UI thread is even more strict and may cause an ANR (Activity not responding) dialog to appear.

One final thought, try to avoid using e.printStackTrace(); in android apps. Instead, use the Log.e("TAG_STRING", e.getMessage(), e); to print errors to the android logging system that you can access from logcat.

All in all, it should looks something like this:

    try {
        mMediaPlayer.setDataSource(videoString);
        holder = mPreview.getHolder();
        mMediaPlayer.setDisplay(holder);
        mMediaPlayer.prepareAsync();
    } catch (IllegalArgumentException e) {
        Log.e("TAG_STRING", e.getMessage(), e);
    } catch (SecurityException e) {
        Log.e("TAG_STRING", e.getMessage(), e);
    } catch (IllegalStateException e) {
        Log.e("TAG_STRING", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("TAG_STRING", e.getMessage(), e);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!