我如何使用原始的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 :(得分:-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.