简体   繁体   中英

how to play a tone from assets folder using Android ringtone manager?

Can i play a tone which is present in assets using Android Ring tone manger? I know i can use the tone copied in Res folder in following manner:

Uri inAppsoundUri = Uri.parse("android.resource://"
            + mAppContext.getPackageName() + "/raw/" + tone);**
ringTone = RingtoneManager.getRingtone(mAppContext,
                    inAppsoundUri);**
ringTone.play();

But when i tried replacing /raw/ with /assets/ in inAppsoundUri, it resulted in error. Actually i want to copy the tones to Sdcard also for some app specific usage for which i have to keep these tones files in assets, and also some times i have to play it through Ringtone manager for which i have to copy the same files in Res/raw folder. So there is unnecessary 2 copies of same tone files are present in the apk which results in larger apk size. So could you please suggest any way to do this both the functions(ie copy to sdcard and play using Android Ringtone mnager) from same place?

I am check it but i think it help you.

Uri inAppsoundUri = Uri.parse("file:///android_asset/tone.mp3"); 

and place tone.mp3 in assert folder.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM