5

のような通知音のURIがありますcontent://media/internal/audio/media/122SoundPool、URIでは機能せず、ファイルパスのapkリソースでのみ機能します。

URI からメディア ファイル パスを取得する方法はありますか? を試してみましUri.getPath()たが、これは を返します/internal/audio/media/122が、これは有効なファイル パスではなく、もちろんSoundPoolそのようなパッチでは機能しません。

実際、通知への実際のパスは/system/media/audio/notifications/allegro.oggであり、次のような URI から取得する方法はありませんcontent://media/internal/audio/media/122

それともそのために使うべきMediaPlayerですか?私はテストしました、それは動作します:

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

MediaPlayer短い通知音を鳴らすには重すぎて困惑しているので、 を使用したいと思いますSoundPool

重量について間違っている場合は教えてくださいMediaPlayer。また、URI で通知音を再生する正しい方法を提案してください。

4

3 に答える 3

0

これを試してフルパスを取得してください:

String path = Environment.getRootDirectory().getAbsolutePath(); //Will return "/system"
path = path + Uri.getPath().subString(9); //To cut "content:/" from the Uri path.
//Then pass this "path" to your SoundPool

あなたが正しいです。音楽やビデオに使用される MediaPlayer とは異なり、SoundPool は、通知などの短いアプリ オーディオ リソースに使用されることを意図しています。MediaPlayer よりもはるかに高速で軽量です。

于 2012-08-21T07:00:48.770 に答える