首页 文章

媒体播放器播放缓冲区的歌曲

提问于
浏览
0

我正试图通过媒体播放器播放直播mp3音频 . 问题是,当我使用URL时,它会阻止UI线程一段时间然后它工作正常 . 但我需要它也会播放带有缓冲的歌曲 .

先谢谢 . 请帮忙 .

try {
             audioPlayer = new MediaPlayer();
            audioPlayer.setOnBufferingUpdateListener(this);
            audioPlayer.setOnCompletionListener(this);
            audioPlayer.setAudioStreamType(useFrontSpeaker ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC);

        try {
            audioPlayer.reset();
            audioPlayer.setDataSource(mSongDetail.getPath());
            audioPlayer.prepare();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        audioDuration = audioPlayer.getDuration();
        audioPlayer.start();

        startProgressTimer();
    } catch (Exception e) {
        if (audioPlayer != null) {
            audioPlayer.reset();
            audioPlayer.release();
            audioPlayer = null;
            isPaused = false;
            MusicPreferance.playingSongDetail = null;
        }
        return false;
    }

1 回答

  • 0

    尝试使用audioPlayer.prepareAsync()asyncHandler,或使用单独的Thread .

相关问题