铃声正在播放默认铃声

铃声正在播放默认铃声,第1张

概述这已从原始帖子更改.基本上发生了什么事,我已经将此显示在手机的铃声列表中.它还选择它.在此代码中,它会在选定铃声后播放铃声(我已将其取出来减小尺寸).似乎正在播放手机的默认铃声.有什么想法吗?谢谢privatevoidringtone(intp){FilenewSoundFile=newFile("/sdcard/

这已从原始帖子更改.

基本上发生了什么事,我已经将此显示在手机的铃声列表中.它还选择它.在此代码中,它会在选定铃声后播放铃声(我已将其取出来减小尺寸).似乎正在播放手机的默认铃声.有什么想法吗?谢谢

private voID ringtone(int p){    file newSoundfile = new file("/sdcard/media/ringtone", "raven.wav");    Uri mUri = Uri.parse("androID.resource://com.fs.hh/"+R.raw.raven);    ContentResolver mCr = getContentResolver();    AssetfileDescriptor soundfile;    try {           soundfile= mCr.openAssetfileDescriptor(mUri, "r");       } catch (fileNotFoundException e) {           soundfile=null;          }       try {          byte[] readData = new byte[1024];          fileinputStream fis = soundfile.createinputStream();          fileOutputStream fos = new fileOutputStream(newSoundfile);          int i = fis.read(readData);          while (i != -1) {            fos.write(readData, 0, i);            i = fis.read(readData);          }          fos.close();          soundfile.close();       } catch (IOException io) {       }       ContentValues values = new ContentValues();       values.put(MediaStore.MediaColumns.DATA, newSoundfile.getabsolutePath());       values.put(MediaStore.MediaColumns.Title, "my ringtone");       values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");       values.put(MediaStore.MediaColumns.SIZE, newSoundfile.length());       values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name);       values.put(MediaStore.Audio.Media.IS_ringtone, true);       values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);       values.put(MediaStore.Audio.Media.IS_ALARM, true);       values.put(MediaStore.Audio.Media.IS_MUSIC, false);       Uri uri = MediaStore.Audio.Media.getContentUriForPath(newSoundfile.getabsolutePath());       mCr.delete(uri, MediaStore.MediaColumns.DATA + "=\"" + newSoundfile.getabsolutePath() + "\"", null);       Uri newUri = mCr.insert(uri, values);      ringtoneManager.setActualDefaultringtoneUri(Soundboard.this, ringtoneManager.TYPE_ringtone, newUri);}

我还尝试在铃声后添加一个/并使其获得字节大小.都没有工作.

我也尝试过这段代码,它会导致相同的问题.它会在通知部分中显示为选中状态,但是正在播放的声音不是正确的声音.听起来像是默认铃声.

private boolean setringtone(int p){    int ressound = whichSound(p); //The R.raw.sound    String fileTitle = fileTitle(p); // sound    String soundTitle = soundTitle(p); // Sound    byte[] buffer=null;    inputStream fIn = getBaseContext().getResources().openRawResource(ressound);    int size=0;    try {    size = fIn.available();    buffer = new byte[size];    fIn.read(buffer);    fIn.close();    } catch (IOException e) {    // Todo auto-generated catch block    return false;    }    String path="/sdcard/media/notification";    String filename=fileTitle+".wav";    boolean exists = (new file(path)).exists();    if (!exists){new file(path).mkdirs();}    fileOutputStream save;    try {    save = new fileOutputStream(path+filename);    save.write(buffer);    save.flush();    save.close();    } catch (fileNotFoundException e) {    // Todo auto-generated catch block    return false;    } catch (IOException e) {    // Todo auto-generated catch block    return false;    }    sendbroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_file, Uri.parse("file://"+path+filename)));    file k = new file(path, filename);    ContentValues values = new ContentValues();    values.put(MediaStore.MediaColumns.DATA, k.getabsolutePath());    values.put(MediaStore.MediaColumns.Title, soundTitle);    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");    values.put(MediaStore.Audio.Media.ARTIST, "HH");    values.put(MediaStore.Audio.Media.IS_ringtone, false);    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);    values.put(MediaStore.Audio.Media.IS_ALARM, false);    values.put(MediaStore.Audio.Media.IS_MUSIC, false);    //Insert it into the database    Uri newUri= this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getabsolutePath()), values);    ringtoneManager.setActualDefaultringtoneUri(    this,    ringtoneManager.TYPE_NOTIFICATION,    newUri    );        return false;      } 

解决方法:

这是最终解决问题的方法.

private boolean setringtone(int p){    int ressound = whichSound(p);    String fileTitle = fileTitle(p);    String soundTitle = soundTitle(p);    byte[] buffer=null;    inputStream fIn = getBaseContext().getResources().openRawResource(ressound);    int size=0;    try {    size = fIn.available();    buffer = new byte[size];    fIn.read(buffer);    fIn.close();    } catch (IOException e) {    // Todo auto-generated catch block    return false;    }    String path=Environment.getExternalStorageDirectory().getPath()+"/media/ringtone/";    String filename=fileTitle+".wav";    boolean exists = (new file(path)).exists();    if (!exists){new file(path).mkdirs();}    fileOutputStream save;    try {    save = new fileOutputStream(path+filename);    save.write(buffer);    save.flush();    save.close();    } catch (fileNotFoundException e) {    // Todo auto-generated catch block    return false;    } catch (IOException e) {    // Todo auto-generated catch block    return false;    }    sendbroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_file, Uri.parse("file://"+path+filename)));    file k = new file(path, filename);    ContentValues values = new ContentValues();    values.put(MediaStore.MediaColumns.DATA, k.getabsolutePath());    values.put(MediaStore.MediaColumns.Title, soundTitle);    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");    values.put(MediaStore.Audio.Media.ARTIST, "");    values.put(MediaStore.Audio.Media.IS_ringtone, true);    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);    values.put(MediaStore.Audio.Media.IS_ALARM, false);    values.put(MediaStore.Audio.Media.IS_MUSIC, false);    //Insert it into the database    Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getabsolutePath());    getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + k.getabsolutePath() + "\"", null);    Uri newUri = getContentResolver().insert(uri, values);     ringtoneManager.setActualDefaultringtoneUri(this, ringtoneManager.TYPE_ringtone, newUri);    return false;      }  

在路径String中,通过添加Environment.getExternatStorageDirectory().getPath()而不是仅添加sdcard,实际上可以播放声音并正常工作.

总结

以上是内存溢出为你收集整理的铃声正在播放默认铃声全部内容,希望文章能够帮你解决铃声正在播放默认铃声所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1070170.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存