LoginSignup
0
0

More than 5 years have passed since last update.

Android で外部アプリを起動して端末内の音声ファイルを再生してみた件

Last updated at Posted at 2017-09-16

概要

内部ストレージに保存されている Music/不協和音.mp3 を再生してみます :arrow_forward:

Screenshot_2017-09-16-02-30-47.png

(※ :copyright: Yahoo!ファイルマネージャーで閲覧)

方法

暗黙的インテントを用いて音楽再生アプリを起動します。

Intent intent = new Intent(Intent.ACTION_VIEW);
File parent = Environment.getExternalStorageDirectory();
String child = Environment.DIRECTORY_MUSIC + "/不協和音.mp3";
intent.setDataAndType(Uri.fromFile(new File(parent, child)), "audio/*");
startActivity(intent);

実行結果

Android 端末内にインテントを処理できる音楽再生アプリが複数インストールされている場合は、起動するアプリを選択するダイアログが表示されます。

Screenshot_2017-09-10-22-36-16.png

アプリケーションを選択後

音楽が再生されました :musical_note:
プレイヤーを閉じると再生が終了します(バックグラウンドでの再生はできませんでした :no_good: )。

サウンドプレイヤー Google Play Music
Screenshot_2017-09-10-23-13-25.png Screenshot_2017-09-10-22-36-24.png
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0