Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Media Player:Url设置不正确_Java_Android_Url_Media Player - Fatal编程技术网

Java Android Media Player:Url设置不正确

Java Android Media Player:Url设置不正确,java,android,url,media-player,Java,Android,Url,Media Player,我尝试了很多从localhost路径播放音乐,但它没有播放我得到了一个错误,因为uri没有正确给出,这意味着它将在下面的代码中捕获块 我在xml文件中设计了两个按钮,分别是开始和停止,然后在java文件中填充uri。有人能帮我纠正下面的代码吗 public class MusicAndroidActivity extends Activity { static MediaPlayer mPlayer; Button buttonPlay; Button buttonStop; @Override

我尝试了很多从localhost路径播放音乐,但它没有播放我得到了一个错误,因为uri没有正确给出,这意味着它将在下面的代码中捕获块

我在xml文件中设计了两个按钮,分别是开始和停止,然后在java文件中填充uri。有人能帮我纠正下面的代码吗

public class MusicAndroidActivity extends Activity {
static MediaPlayer mPlayer;
Button buttonPlay;
Button buttonStop;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    buttonPlay = (Button) findViewById(R.id.play);
    buttonPlay.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Uri myUri = Uri.parse("http://192.168.1.7/Android/music/vande.mp3");
            mPlayer = new MediaPlayer();
            mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            try {
                mPlayer.setDataSource(getApplicationContext(), myUri);
            } catch (IllegalArgumentException e) {
                Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            } catch (SecurityException e) {
                Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            } catch (IllegalStateException e) {
                Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                mPlayer.prepare();
            } catch (IllegalStateException e) {
                Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            }
            mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                public void onPrepared(MediaPlayer mp) {                        
                    //mp.start();                       
                    mPlayer.start();
                }
            });

        }
    });

    buttonStop = (Button) findViewById(R.id.stop);
    buttonStop.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            if(mPlayer!=null && mPlayer.isPlaying()){
                mPlayer.stop();
            }
        }
    });
}

protected void onDestroy() {
    super.onDestroy();

    if (mPlayer != null) {
        mPlayer.release();
        mPlayer = null;
    }
}}
每次我在捕捉块上着陆时异常 我查了我的航海日志,它告诉我


我没有使用Gpu,因为我会出现渲染错误,是因为这个原因还是我没有在程序中使用上面uri的语法

你检查了吗@ErsinGülbahar我在eclipse中尝试了apk文件,它告诉我与未设置url相同correctly@ErsinGülbahar不,我没有试过,我应该把这个代码转换成你给我看的代码吗?你可以检查一下我的代码中有什么错误@Ersin Gülbahar@Raghunandan你能说出上面代码中的错误吗