Android SDK设置铃声问题
我正在尝试在模拟器/手机上添加并设置默认铃声。铃声已下载并存储在应用程序文件夹/dada/dada/com.xxx/ringtones 中。铃声是ogg文件。
我使用以下代码来添加和设置铃声:
public void setRingtone() {
aajoAsset asset = null;
asset = mXXXX.getAssetManager().getCurrentRingtoneAsset();
if (asset != null && asset.isSaved()/* && !asset.getName().equals(mLastAssetName)*/) {
String filepath = asset.getDirectoryPath() + asset.getFilename();
File ringtoneFile = new File(filepath);
if (LOG) {
Log.i(TAG, "Sending Intent : " + Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
}
mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + asset.getDirectoryPath() + asset.getFilename())));
ContentValues content = new ContentValues();
content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath());
content.put(MediaStore.MediaColumns.TITLE, "1234");
content.put(MediaStore.MediaColumns.SIZE, asset.getSize());
content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
content.put(MediaStore.Audio.Media.ARTIST, "1234");
content.put(MediaStore.Audio.Media.DURATION, 4800);
content.put(MediaStore.Audio.Media.IS_RINGTONE, true);
content.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
content.put(MediaStore.Audio.Media.IS_ALARM, false);
content.put(MediaStore.Audio.Media.IS_MUSIC, false);
if (LOG) {
Log.i(TAG, "the absolute path of the file is : " + ringtoneFile.getAbsolutePath());
}
Uri uri = MediaStore.Audio.Media.getContentUriForPath(
ringtoneFile.getAbsolutePath());
Uri newUri = mContext.getContentResolver().insert(uri, content);
if (LOG) {
Log.i(TAG,"the ringtone uri is : " + newUri);
}
RingtoneManager.setActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_RINGTONE, newUri);
mLastAssetName = asset.getName();
}
代码执行正常,铃声显示在铃声列表中,但是当我单击它来测试它或当我模拟来电时,我在 LogCat 中收到以下错误:
DEBUG/MediaPlayer(1230): Couldn't open file on client side, trying server side
ERROR/MediaPlayerService(33): Couldn't open fd for content://media/internal/audio/media/1
ERROR/MediaPlayer(1230): Unable to to create media player
ERROR/RingtoneManager(1230): Failed to open ringtone content://media/internal/audio/media/1
我有在许多论坛中搜索了解决方案,但没有找到任何解决方案。
非常欢迎任何帮助
谢谢
I am trying to add and set the default ringtone on the emulator/phone. The ringtone has been downloaded and is stored in the application folder /dada/dada/com.xxx/ringtones. the ringtones are ogg files.
I use the following code to add and set the ringtone:
public void setRingtone() {
aajoAsset asset = null;
asset = mXXXX.getAssetManager().getCurrentRingtoneAsset();
if (asset != null && asset.isSaved()/* && !asset.getName().equals(mLastAssetName)*/) {
String filepath = asset.getDirectoryPath() + asset.getFilename();
File ringtoneFile = new File(filepath);
if (LOG) {
Log.i(TAG, "Sending Intent : " + Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
}
mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + asset.getDirectoryPath() + asset.getFilename())));
ContentValues content = new ContentValues();
content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath());
content.put(MediaStore.MediaColumns.TITLE, "1234");
content.put(MediaStore.MediaColumns.SIZE, asset.getSize());
content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
content.put(MediaStore.Audio.Media.ARTIST, "1234");
content.put(MediaStore.Audio.Media.DURATION, 4800);
content.put(MediaStore.Audio.Media.IS_RINGTONE, true);
content.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
content.put(MediaStore.Audio.Media.IS_ALARM, false);
content.put(MediaStore.Audio.Media.IS_MUSIC, false);
if (LOG) {
Log.i(TAG, "the absolute path of the file is : " + ringtoneFile.getAbsolutePath());
}
Uri uri = MediaStore.Audio.Media.getContentUriForPath(
ringtoneFile.getAbsolutePath());
Uri newUri = mContext.getContentResolver().insert(uri, content);
if (LOG) {
Log.i(TAG,"the ringtone uri is : " + newUri);
}
RingtoneManager.setActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_RINGTONE, newUri);
mLastAssetName = asset.getName();
}
The code executes fine and the ringtone shows in the ringtone list but when I click on it to test it or when I simulate a incoming call I get the following errors in LogCat:
DEBUG/MediaPlayer(1230): Couldn't open file on client side, trying server side
ERROR/MediaPlayerService(33): Couldn't open fd for content://media/internal/audio/media/1
ERROR/MediaPlayer(1230): Unable to to create media player
ERROR/RingtoneManager(1230): Failed to open ringtone content://media/internal/audio/media/1
I have searched for solutions in many forums and cannot find any.
any help is most welcome
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论