Anroid开发 之 音频文件的循环播放
public class MainActivity extends Activity { private MediaPlayer musicPlayer; private File musicFile; //音乐文件存放地址 private String musicPath="/sdcard/ftpdata/Apologize.mp3"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); musicFile = new File(musicPath); //判断文件是否存在 if (musicFile.exists()) { musicPlayer = MediaPlayer.create(this, Uri.parse(musicFile.getAbsolutePath())); musicPlayer.start(); }else { System.out.println("the file no exist!"); } //监听音频播放完的代码,实现音频的自动循环播放 musicPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer arg0) { musicPlayer.start(); musicPlayer.setLooping(true); } }); }
补充:移动开发 , Android ,