Android-媒体播放器与测试设备的流问题 [英] Android- Mediaplayer streaming issue with test devices

查看:119
本文介绍了Android-媒体播放器与测试设备的流问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个给定的流媒体数据源一个媒体播放器。我有两个测试设备:HTC霹雳和三星Galaxy SII扶摇直上。

HTC的设备能够流文件完全没有问题;然而,GALAXY SII不能在所有,给了我一堆媒体播放器错误codeS的。

我执行有关媒体播放器一切正常......但是,我不能让我解决这个问题的头......怎么会是会在一个手机上运行而不是其他?其相同的链接。

任何想法?从下面的设备日志。如有必要,也可以发表我的code。

谢谢!

从HTC设备登录:

  06-25 18:19:23.192:D / MainAudioService(23564):下一首歌曲是:http://soundcloud.com/stopdroprave/chromeo-night-by-night/下载/ S-bpPu1
06-25 18:19:26.675:W / MediaPlayer的(23564):信息/警告(1,902)
06-25 18:19:28.497:D / dalvikvm(23564):GC_EXTERNAL_ALLOC释放515K,50%的自由3544K / 7047K,外部477K / 989K,暂停22毫秒
06-25 18:19:31.250:D / MainAudioService(23564):在几分钟内歌曲长度为:-6:5
06-25 18:19:31.250:D / MediaPlayer的(23564):开始()在
06-25 18:19:31.250:D / MediaPlayer的(23564):开始()出
06-25 18:19:31.310:I / MediaPlayer的(23564):信息(1902)
06-25 18:19:31.310:D / MainAudioService(23564):在信息中的MP:1和902
06-25 18:19:50.909:D / MediaPlayer的(23564):停止()在
06-25 18:19:50.919:D / MediaPlayer的(23564):停止()出
06-25 18:19:50.919:D / MediaPlayer的(23564):复位()的
06-25 18:19:50.929:D / MediaPlayer的(23564):reset()的出
06-25 18:19:50.939:D / MainAudioService(23564):下一首歌曲是:http://soundcloud.com/stopdroprave/subvibe-mizukis-last-chance/download/s-Jaezp
06-25 18:19:55.433:W / MediaPlayer的(23564):信息/警告(1,902)
06-25 18:19:58.656:D / dalvikvm(23564):GC_EXTERNAL_ALLOC释放503K,57%免费3099K / 7047K,1102K外部/ 1614K,暂停45ms
06-25 18:20:00.3​​38:D / MainAudioService(23564):在几分钟内歌曲长度为:-6:39
06-25 18:20:00.3​​38:D / MediaPlayer的(23564):开始()在
06-25 18:20:00.3​​38:D / MediaPlayer的(23564):开始()出
06-25 18:20:00.408:I / MediaPlayer的(23564):信息(1902)

从SGSII日志:

  06-25 18:27:32.797:E / MediaPlayer的(24277):停止叫状态0
06-25 18:27:32.797:E / MediaPlayer的(24277):错误(-38,0)
06-25 18:27:32.807:D / MainAudioService(24277):下一首歌曲是:http://soundcloud.com/stopdroprave/doctor-p-watch-out-crazes-locd/download/s-qQhJP
06-25 18:27:32.807:E / MediaPlayer的-JNI(24277)的setDataSource:在外面JNI路径为x @
06-25 18:27:33.498:E / MediaPlayer的(24277):错误(1,-2147483648)
06-25 18:27:33.498:E / MediaPlayer的(24277):错误(1,-2147483648)
06-25 18:27:33.498:D / MainAudioService(24277):错误MP:1和-2147483648
06-25 18:27:33.498:E / MediaPlayer的(24277):停止状态称为0
06-25 18:27:33.498:E / MediaPlayer的(24277):错误(-38,0)
06-25 18:27:33.508:D / MainAudioService(24277):下一首歌曲是:http://soundcloud.com/stopdroprave/digitalism-circle-eric-prydz/download/s-XlYFv
06-25 18:27:33.508:E / MediaPlayer的-JNI(24277)的setDataSource:在外面JNI路径为x @
06-25 18:27:34.149:E / MediaPlayer的(24277):错误(1,-2147483648)
06-25 18:27:34.149:E / MediaPlayer的(24277):错误(1,-2147483648)
06-25 18:27:34.149:D / MainAudioService(24277):错误MP:1和-2147483648

编辑:

这里是我设置的数据源....

  SdrPlaylist P = mPlaylist.get(currentNum);            字符串路径= p.songUrl;            artistInfo = p.songName;
            nextSong = Toast.makeText(getApplicationContext(),
                    缓冲下一首乐曲......,Toast.LENGTH_LONG);
            nextSong.setGravity(Gravity.TOP,0,110);
            nextSong.show();            尝试{
                Log.d(TAG,下一首歌曲是:+路径);                mediaPlayer.setDataSource(路径);                。媒体播放器prepareAsync();
            }赶上(抛出:IllegalArgumentException五){
                e.printStackTrace();
            }赶上(IllegalStateException异常五){
                e.printStackTrace();
            }赶上(IOException异常五){
                e.printStackTrace();
            }


解决方案

为MediaPlayer的状态文档:


  

对于流,你应该叫prepareAsync(),它立即返回,而不是阻塞,直到足够的数据已经被缓存。


所以我试图着手行动。您需要改用在preparedListener调用启动()为您假设它返回以后prepare完成的。

 私人MediaPlayer的熔点为新的MediaPlayer();
mp.setOn preparedListener(新MediaPlayer.On preparedListener(){
    @覆盖
    在prepared(MediaPlayer的为arg0)公共无效{
        mp.start();    }
});mp.reset(); //< ---你可能不应该需要这个位置。
mp.setDataSource(soundUri);
。MP prepareAsync();

您将保证不会在MediaPlayer之前调用start()这样是prepared。

如果您仍然有在此之后改变我的下一个猜测的麻烦是,它是$ C $抄送相关。在Android的媒体播放是有点挑剔,这是流媒体千真万确。什么类型的文件是你想打?

I currently have a mediaplayer that is given a streamable datasource. I have two test devices: HTC Thunderbolt and a Samsung Galaxy SII Skyrocket.

The HTC device is able to stream the files perfectly fine; however, the galaxy sII cannot at all, and gives me a bunch of media player error codes.

I am implementing everything related to the media player properly...however, i can't get my head around this issue...how come it'll work on one phone but not the other? its the same link.

Any ideas? Logs from the devices below. Can post my code if necessary as well.

Thanks!

Log from the HTC device:

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)

Log from the 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

EDIT:

here is where i set the datasource....

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();
            }

解决方案

The docs for MediaPlayer state:

For streams, you should call prepareAsync(), which returns immediately, rather than blocking until enough data has been buffered.

So I would start by trying that. You'll need to use the OnPreparedListener to call start() for you instead of assuming that prepare is finished after it returns.

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();

That way you will be guaranteed not to be calling start() before the MediaPlayer is prepared.

If you are still having trouble after this change my next guess is that it is codec related. Media playback on android is a bit finicky, and that is doubly true for streaming Media. What type of file are you trying to play?

这篇关于Android-媒体播放器与测试设备的流问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆