通过URI播放音频通知 [英] Play notification audio by URI

查看:147
本文介绍了通过URI播放音频通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有通知声音的URI,如内容:// /内部/音频/媒体/ 122 ,但的Soundpool 不URI的工作,其工作原理与文件路径只有APK资源。

I have URI of the notification sound, like content://media/internal/audio/media/122, but SoundPool doesn't work with URIs, it works with only apk resources of file paths.

有没有办法从URI获取媒体文件的路径?我试图 Uri.getPath(),返回 /内部/音频/媒体/ 122 ,但这不是有效的文件路径,当然,的Soundpool 不打补丁等工作。

Is there a way to get media file path from URI? I tried Uri.getPath(), which returns /internal/audio/media/122, but this isn't valid file path, and of course SoundPool doesn't work with such patch.

其实对于通知的现实路径是 /system/media/audio/notifications/allegro.ogg ,我看没有办法从URI得到它像内容:// /内部/音频/媒体/ 122

Actually the real path to the notification is /system/media/audio/notifications/allegro.ogg , and I see no way to get it from URI like content://media/internal/audio/media/122

或者我应该使用的MediaPlayer 是什么?我测试,它的工作原理:

Or should I use MediaPlayer for that? I tested, it works:

           MediaPlayer mp = MediaPlayer.create(this, "content://media/internal/audio/media/122");
           mp.start();

我很困惑,因为的MediaPlayer 似乎太沉重,只是打短通知声音,所以我倒是preFER使用的Soundpool

I'm confused because MediaPlayer seems to be too heavy to just play short notification sound, so I'd prefer to use SoundPool.

请告诉我,如果我错了的MediaPlayer 的重量,并建议通过URI播放通知声音正确的方法。

Please tell me if I'm wrong about MediaPlayer weight, and suggest correct way to play notification sound by its URI.

推荐答案

好了,我得到了由URI播放音频的最简单的方法:

Well, I got the easiest way to play audio by URI:

RingtoneManager.getRingtone(this, Uri.parse("content://media/internal/audio/media/122")).play();

我觉得这是最好的我所能实现的。

I think this is the best what i could achieve.

这篇关于通过URI播放音频通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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