android.media.MediaPlayer第二个参数

时间:2016-03-16 19:30:44

标签: java android

在页面上:

http://developer.android.com/guide/topics/media/mediaplayer.html

关闭该页面的示例代码:

添加以下两项内容:

  1. import android.R.raw;
  2. 致电getApplicationContext();
  3. MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext();, R.raw.sound_file_1);
    mediaPlayer.start(); // no need to call prepare(); create() does that for you
    

    问题?: R.raw.sound_file_1参数MediaPlayer.create如何将其定义为文件,例如/dev/sda1/mediafile.xxx

    感谢您提前提供任何帮助...... Michael

1 个答案:

答案 0 :(得分:0)

您可以传递Uri作为第二个参数。要创建Uri,请执行以下操作:

Uri uri = Uri.create("/dev/sda1/mediafile.xxx")

然后将其传递给MediaPlayer.create(),如此:

MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), uri)