安卓的mediaplayer 不能实现播放?



 btn_send_activity_play.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
               String s = Environment.getExternalStorageDirectory().getAbsolutePath().toString() 
                            + "/netease/cloudmusic/Music";

                s += "/sad.mp3";
                Log.i("joursion",s);
                File f = new File(s);

                //检查是否存在
                if(!f.exists()){
                    Log.i("joursion", "not exit");
                }
                else
                    Log.i("joursion", " exit");

                mediaPlayer.reset();
                mediaPlayer.setDataSource(s);
                Log.i("joursion", " exit");
                if (!mediaPlayer.isPlaying()) {
                    Log.i("joursion", "play");
                    mediaPlayer.prepare();
                    mediaPlayer.start();
                } else {
                    mediaPlayer.pause();
                }

            } catch (IOException e) {
                Log.e("joursion","play err");
            }
        }
    });

这是权限
图片描述

这是log日志,文件是存在的,但是 不能播放
图片描述

media-player Android

戏言スピーカー 9 years, 5 months ago

你可以把文件放到raw文件夹下,例如:a.mp4文件,直接调用mediaplayer=new MediaPlayer(this,R.raw.a.mp4);
mediaplayer.start();

触手伸遍全世界 answered 9 years, 5 months ago

Your Answer