【问题标题】:How to set custom music on Android?如何在 Android 上设置自定义音乐?
【发布时间】:2017-06-27 14:32:29
【问题描述】:

我想做一个音乐播放器,可以播放我存储卡上的所有音乐。 我使用此代码播放音乐,但我无法播放存储卡中的音乐,只能在原始文件夹中播放。

MediaPlayer mp = MediaPlayer.create(this, R.id.raw.audio.mp3)

我应该怎么做才能播放 SD 卡中的音乐?

【问题讨论】:

标签: android android-mediaplayer


【解决方案1】:

你会想做这样的事情

    Uri song = Uri.parse(location-of-song); //location-of-song is where the music is on the sd card
    mPlayer = new MediaPlayer();
    mPlayer.setDataSource(getApplicationContext(), song);
    mPlayer.start();

【讨论】:

【解决方案2】:

使用带有 URI 的 create 版本,并提供要播放的本地文件的 URI。

【讨论】:

  • 喜欢这个?文件:///sdcard/music.mp3
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-29
  • 2014-07-01
相关资源
最近更新 更多