2012-04-12 91 views
1

我想使用系統音頻/視頻播放器播放我的原始文件夾中的聲音,但我一直在獲得相同的「沒有發現處理意圖」活動消息(例外)意圖。意圖從原始文件夾播放聲音

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse("android.resource://mypackagename/" + R.raw.audiofile), "audio/*"); 
startActivity(intent); 

任何想法?謝謝!

+0

R.raw.audiofile是一個整數。不是文件名。 – 2012-06-12 20:56:59

回答

0

請嘗試以下內容(其中音效檔是沒有擴展名的原始文件夾中的文件的名稱只能使用小寫字符,請。):

MediaPlayer player = MediaPlayer(this,R.raw.soundfile); 

player.prepare(); 
player.start(); 

。 。 。

player.stop(); 
player.reset(); 
player.release(); 
player = null; 

找到here

0

意圖系統的工作方式是,您的應用程序基本上是說:「嘿Android,我有這個網址,我想查看它。手機上有應用程序會這樣做嗎?

對於http網址,您的瀏覽器已安裝在手機上,對於Google Play網址,它會向您顯示Google Play商店作爲選項等等。如果您的手機上沒有應用程序這將處理音頻資源(沒有一個默認安裝,無論這意味着什麼)。

就像德克說的,你必須使用MediaPlayer播放你的資源。 MediaPlayer頁面非常好聽:http://developer.android.com/reference/android/media/MediaPlayer.html