在默认音乐播放器上播放歌曲-Android [英] Play song on default music player - android

查看:201
本文介绍了在默认音乐播放器上播放歌曲-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用显示了SD卡中歌曲的列表.我希望能够在默认播放器上播放歌曲.我已经掌握了有关这首歌的所有数据:id,标题,专辑,艺术家,路径...

My app show list of song from sd card. I want to be able to play the song on the default player. I've got all the data about the song: id, title, album, artist, path...

有没有办法启动默认播放器来播放歌曲?

Is there a way to launch the default player to play the song?

我尝试过的事情:

  1. 使用Intent.CATEGORY_APP_MUSIC.我可以启动默认播放器,但无法设置歌曲. Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_MUSIC)打开默认的音乐应用程序. 但是intent.setData(Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id))会引发找不到意图的异常.

  1. Using Intent.CATEGORY_APP_MUSIC. I can launch the default player, but can't set the song. Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_MUSIC) open the default music app. Howeverintent.setData(Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id)) throws exception that intent not found.

使用不推荐使用的MediaStore.INTENT_ACTION_MUSIC_PLAYER.找不到活动. Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER).setDataAndType(Uri.fromFile(songFile), "audio/*")

Using deprecated MediaStore.INTENT_ACTION_MUSIC_PLAYER. Activity not found. Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER).setDataAndType(Uri.fromFile(songFile), "audio/*")

注意:我要启动外部播放器,而不是在我的应用中启动.

Note: I want to launch External player, not in my app.

更新:看起来像Google Now硬编码的Play音乐和Youtube支持.

Update: Looks like Google Now hardcoded Play Music and Youtube support.

推荐答案

如果您要在设备上启动默认的音乐播放器应用,请尝试以下操作:

If you would like to start the default music player app on the device, should try this:

Intent intent = new Intent();  
intent.setAction(android.content.Intent.ACTION_VIEW);  
File file = new File(YOUR_SONG_URI);  
intent.setDataAndType(Uri.fromFile(file), "audio/*");  
startActivity(intent);

这篇关于在默认音乐播放器上播放歌曲-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆