新人求教,关于在安卓做一个音频播放器时遇到的问题
我是一名大二的学生,在自学安卓开发,跟着教学视频做一个简单的音频播放器,但遇到了一些问题,这是我的界面
下面是我的MainActivity.java
package com.example8;
import java.io.IOException;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.SeekBar;
public class MainActivity extends Activity {
private SeekBar progress;
private ImageButton ppIB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress = (SeekBar) findViewById(R.id.progressSB);
ppIB = (ImageButton) findViewById(R.id.ppIB);
}
public void onClick(View view) throws Exception {
String url ="/mnt/sdcard/2ne1 - Do You Love Me";
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
红色的那行提醒信息为Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead
请大家帮帮我,拜托了 安卓 教学
[解决办法]
首先你有权限不
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>