安卓的MediaPlayer无法播放网络媒体:prepare失败:状态=为0x1 [英] Android MediaPlayer can't play web media:Prepare failed.: status=0x1

查看:2479
本文介绍了安卓的MediaPlayer无法播放网络媒体:prepare失败:状态=为0x1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打从Web服务的一首歌,我写了code如下

 保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.content);

    startButton =(的ImageButton)findViewById(R.id.start);

    意向意图= getIntent();
    mp3Path = intent.getStringExtra(mp3Path);

    球员=新的MediaPlayer();

    startButton.setOnClickListener(新OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            尝试 {
                如果(玩家!= NULL)
                    player.stop();
                player.setDataSource(mp3Path);
                播放器prepare()。
                player.start();
            }赶上(IllegalStateException异常E){
                e.printStackTrace();
            }赶上(IOException异常E){
                e.printStackTrace();
            }
        }
    });
}
 

但是,当我点击该按钮,它会抛出以下异常,并告诉我大概有prepare错误:

  04-13 17:23:13.186:E​​ / MediaPlayer的(401):停止调用状态1
04-13 17:23:13.186:E​​ / MediaPlayer的(401):错误(-38,0)
04-13 17:23:13.206:E / MediaPlayer的(401):错误(1,-2147483648)
04-13 17:23:13.206:W / System.err的(401):产生java.io.IOException:prepare失败:状态=为0x1
04-13 17:23:13.226:W / System.err的(401):在android.media.MediaPlayer prepare(本机方法)
04-13 17:23:13.226:W / System.err的(401):在com.Android.SampleActivity $ 1.onClick(SampleActivity.java:50)
 

解决方案

您需要实现流媒体播放器。下面是一个<一个href="http://davanum.word$p$pss.com/2007/12/29/android-videomusic-player-sample-from-local-disk-as-well-as-remote-urls/"相对=nofollow>为例的。希望它会帮助你。

I want to play a song from web service, and I wrote code as follow

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content);

    startButton = (ImageButton) findViewById(R.id.start);

    Intent intent = getIntent();
    mp3Path = intent.getStringExtra("mp3Path");

    player = new MediaPlayer();

    startButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                if(player != null)
                    player.stop();
                player.setDataSource(mp3Path);
                player.prepare();
                player.start();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}

But when I click that button, it throws the following exception and I'm told there are errors about prepare:

04-13 17:23:13.186: E/MediaPlayer(401): stop called in state 1
04-13 17:23:13.186: E/MediaPlayer(401): error (-38, 0)
04-13 17:23:13.206: E/MediaPlayer(401): error (1, -2147483648)
04-13 17:23:13.206: W/System.err(401): java.io.IOException: Prepare failed.: status=0x1
04-13 17:23:13.226: W/System.err(401):  at android.media.MediaPlayer.prepare(Native Method)
04-13 17:23:13.226: W/System.err(401):  at com.Android.SampleActivity$1.onClick(SampleActivity.java:50)

解决方案

You Need to implement Streaming Media Player. Here is an Example. Hope it will help you.

这篇关于安卓的MediaPlayer无法播放网络媒体:prepare失败:状态=为0x1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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