2

我目前有一个媒体播放器,它被赋予了一个可流式传输的数据源。我有两个测试设备:HTC Thunderbolt 和三星 Galaxy SII Skyrocket。

HTC 设备能够完美地流式传输文件;但是,galaxy sII 根本不能,并且给了我一堆媒体播放器错误代码。

我正在正确实施与媒体播放器相关的所有内容...但是,我无法解决这个问题...为什么它可以在一部手机上运行,​​而在另一部手机上不行?它是相同的链接。

有任何想法吗?来自以下设备的日志。如有必要,也可以发布我的代码。

谢谢!

从 HTC 设备登录:

06-25 18:19:23.192: D/MainAudioService(23564): next song is: http://soundcloud.com/stopdroprave/chromeo-night-by-night/download/s-bpPu1
06-25 18:19:26.675: W/MediaPlayer(23564): info/warning (1, 902)
06-25 18:19:28.497: D/dalvikvm(23564): GC_EXTERNAL_ALLOC freed 515K, 50% free 3544K/7047K, external 477K/989K, paused 22ms
06-25 18:19:31.250: D/MainAudioService(23564): Song length in minutes is: -6:5
06-25 18:19:31.250: D/MediaPlayer(23564): start() in
06-25 18:19:31.250: D/MediaPlayer(23564): start() out
06-25 18:19:31.310: I/MediaPlayer(23564): Info (1,902)
06-25 18:19:31.310: D/MainAudioService(23564): On Info in MP: 1and 902
06-25 18:19:50.909: D/MediaPlayer(23564): stop() in
06-25 18:19:50.919: D/MediaPlayer(23564): stop() out
06-25 18:19:50.919: D/MediaPlayer(23564): reset() in
06-25 18:19:50.929: D/MediaPlayer(23564): reset() out
06-25 18:19:50.939: D/MainAudioService(23564): next song is: http://soundcloud.com/stopdroprave/subvibe-mizukis-last-chance/download/s-Jaezp
06-25 18:19:55.433: W/MediaPlayer(23564): info/warning (1, 902)
06-25 18:19:58.656: D/dalvikvm(23564): GC_EXTERNAL_ALLOC freed 503K, 57% free 3099K/7047K, external 1102K/1614K, paused 45ms
06-25 18:20:00.338: D/MainAudioService(23564): Song length in minutes is: -6:39
06-25 18:20:00.338: D/MediaPlayer(23564): start() in
06-25 18:20:00.338: D/MediaPlayer(23564): start() out
06-25 18:20:00.408: I/MediaPlayer(23564): Info (1,902)

来自 SGSII 的日志:

06-25 18:27:32.797: E/MediaPlayer(24277): stop called in state 0
06-25 18:27:32.797: E/MediaPlayer(24277): error (-38, 0)
06-25 18:27:32.807: D/MainAudioService(24277): next song is: http://soundcloud.com/stopdroprave/doctor-p-watch-out-crazes-locd/download/s-qQhJP
06-25 18:27:32.807: E/MediaPlayer-JNI(24277): setDataSource: outside path in JNI is �x@
06-25 18:27:33.498: E/MediaPlayer(24277): error (1, -2147483648)
06-25 18:27:33.498: E/MediaPlayer(24277): Error (1,-2147483648)
06-25 18:27:33.498: D/MainAudioService(24277): Error in MP: 1 and -2147483648
06-25 18:27:33.498: E/MediaPlayer(24277): stop called in state 0
06-25 18:27:33.498: E/MediaPlayer(24277): error (-38, 0)
06-25 18:27:33.508: D/MainAudioService(24277): next song is: http://soundcloud.com/stopdroprave/digitalism-circle-eric-prydz/download/s-XlYFv
06-25 18:27:33.508: E/MediaPlayer-JNI(24277): setDataSource: outside path in JNI is �x@
06-25 18:27:34.149: E/MediaPlayer(24277): error (1, -2147483648)
06-25 18:27:34.149: E/MediaPlayer(24277): Error (1,-2147483648)
06-25 18:27:34.149: D/MainAudioService(24277): Error in MP: 1 and -2147483648

编辑:

这是我设置数据源的地方....

SdrPlaylist p = mPlaylist.get(currentNum);

            String path = p.songUrl;

            artistInfo = p.songName;
            nextSong = Toast.makeText(getApplicationContext(),
                    "Buffering Next Song...", Toast.LENGTH_LONG);
            nextSong.setGravity(Gravity.TOP, 0, 110);
            nextSong.show();

            try {
                Log.d(TAG, "next song is: " + path);

                mediaPlayer.setDataSource(path);

                mediaPlayer.prepareAsync();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
4

2 回答 2

2

MediaPlayer状态的文档:

对于流,您应该调用prepareAsync(),它会立即返回,而不是阻塞直到缓冲足够的数据。

所以我会从尝试开始。您需要使用 OnPreparedListener 为您调用 start() 而不是假设准备在它返回后完成。

private MediaPlayer mp = new MediaPlayer();
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer arg0) {
        mp.start();

    }
});

mp.reset(); //<--- you probably shouldn't need this here.
mp.setDataSource(soundUri);
mp.prepareAsync();

这样你就可以保证在 MediaPlayer 准备好之前不会调用 start() 。

如果您在此更改后仍然遇到问题,我的下一个猜测是它与编解码器相关。android 上的媒体播放有点挑剔,对于流媒体来说更是如此。您要播放什么类型的文件?

于 2012-06-26T00:13:28.977 回答
0

因为这似乎是您设置媒体播放器的数据源的问题,所以应该这样做:

private MediaPlayer mp = new MediaPlayer();
mp.reset();
mp.setDataSource(soundUri);
mp.prepare();
mp.start();

或者您可以在此处查看完整答案:https ://stackoverflow.com/a/9061259/1084764

于 2012-06-26T00:04:57.680 回答