2014-09-30 81 views
0

如何使用原始鈴聲保存mp3文件?使用mp3原始鈴聲

我已經把這個代碼,但不工作:

Uri path = Uri.parse("android.resource://mypack/raw/soundmp3"); 
 
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),RingtoneManager.TYPE_RINGTONE,path); 
 
Log.i("TESTT", "Ringtone Set to Resource: " + path.toString()); 
 
RingtoneManager.getRingtone(getApplicationContext(), path).play();

我已經在使用權限:

<uses-permission android:name="android.permission.WRITE_SETTINGS" /> 
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /> 
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 
+0

可能重複[如何設置鈴聲在Android從我的活動?](http://stackoverflow.com/questions/1271777/how-to-s et-ringtone-in-android-from-my-activity) – m0skit0 2014-09-30 17:50:58

回答

-1
int resID=getResources().getIdentifier(fname, "raw", getPackageName()); 

MediaPlayer mediaPlayer=MediaPlayer.create(this,resID); 
mediaPlayer.start(); 


You can not save anything on runtime in raw folder coz it is read-only. 
You have to put your file in raw folder before making a build. 
+0

我無法保存原始文件並播放該文件,我想保存爲鈴聲... Tks !!! – Doug 2014-09-30 17:48:24

+0

我認爲OP意味着將該鈴聲保存爲他手機的默認設置。 – 2014-09-30 17:48:56

+0

我必須在fname中輸入什麼? – Doug 2014-09-30 17:53:09