Android Mediaplayer和RTSP Playback的问题

时间:2015-05-05 16:55:55

标签: android android-mediaplayer rtsp

我在Android中遇到RTSP音频流播放问题。基本上,在意外结束之前,流可以在大约4-5分钟内播放。我不确定它是客户端还是服务器端。这是我得到的错误:

05-05 10:47:38.040    2171-2179/com.ciamradio.ciamradio W/MediaPlayer-JNI﹕ MediaPlayer finalized without being released
05-05 10:47:38.040     931-1269/? D/NuPlayerDriver﹕ reset(0xb58f7520)
05-05 10:47:38.168     931-2187/? I/ARTSPConnection﹕ status: RTSP/1.0 200 OK
05-05 10:47:38.169     931-2187/? I/RTSPSource﹕ TEARDOWN completed with result 0 (Success)
05-05 10:47:38.174     931-2187/? I/qtaguid﹕ Untagging socket 16 failed errno=-2
05-05 10:47:38.175     931-2187/? E/HTTPBase﹕ Failed untagging socket 16 (My UID=1013)
05-05 10:47:38.177     931-2187/? E/ARTSPConnection﹕ Server unexpectedly closed the connection.
05-05 10:47:38.182     931-2186/? D/NuPlayerDriver﹕ notifyResetComplete(0xb58f7520)

以下是我使用的媒体播放器的代码。

 Uri myUri = Uri.parse("rtsp://ciam.audio.netbroadcasting.tv:1935/ciam-live/ciamfv.stream"); // initialize Uri here

        try {
            MediaPlayer mediaPlayer = new MediaPlayer();
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mediaPlayer.setDataSource(String.valueOf(myUri));
            mediaPlayer.prepare();
            android.os.SystemClock.sleep(1000);

            mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.start();
                }
            });
            mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                public void onCompletion(MediaPlayer mMediaPlayer) {
                    mMediaPlayer.release();
                }
            });
       }
       catch (IOException e) {
           Log.d("CIAM", "create failed:");

        }

1 个答案:

答案 0 :(得分:0)

基本上问题是垃圾收集最终确定了媒体播放器,因为我没有在try / catch语句之外定义MP。固定代码是:

Uri myUri = Uri.parse("rtsp://ciam.audio.netbroadcasting.tv:1935/ciam-live/ciamfv.stream"); // initialize Uri here
MediaPlayer mediaPlayer = new MediaPlayer();
        try {

            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mediaPlayer.setDataSource(String.valueOf(myUri));
            mediaPlayer.prepare();
            android.os.SystemClock.sleep(1000);

            mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.start();
                }
            });
            mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                public void onCompletion(MediaPlayer mMediaPlayer) {
                    mMediaPlayer.release();
                }
            });
       }
       catch (IOException e) {
           Log.d("CIAM", "create failed:");

        }