在我的应用程序中,我有一些.caf音频文件(格式:IMA 4:1,立体声,44.100 kHz)。我面临的问题是这些音频文件播放按钮操作(每个铃声一个按钮)。他们在iphone上播放良好(ios版本3到5),但我不能够在iPod上听它。我已经完成了所有声音设置更改,如其他站点上描述的解决方案,但没有任何反应 另外ipod没有卡在耳机模式(这个问题发生在我们插入耳机时,而任何音频文件播放)。所以请尽快给任何解决方案。.caf file in app not playing in iPod
回答
首先您导入,然后框架使用下面的代码:用这种方法
#import <AudioToolbox/AudioToolbox.h>
通话,只要你想:
[self BackgroundSound:@"sounf file name"];//must have in resource(.wav,.mp3,.caf)
写此功能通过上述方法调用:
- (void)BackgroundSound:(NSString *) name
{
NSString *spath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:name];
AVAudioPlayer* BackgroundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:spath] error:nil];
BackgroundPlayer.numberOfLoops = -1; // set to -1 to loop repeated
BackgroundPlayer.volume = 0.5; // value is from 0 to 1.0 (float)
[BackgroundPlayer play]; // play
}
在我的应用程序中工作在iPad/iPhone。我希望,这也是对你的帮助。
ur和我的代码之间的唯一区别是“audioplayer.volume = 0.5”,这可能是原因,但即使在我的代码中放入音频文件后也不会发声。 –
第一,你必须尝试另一个声音文件,如“.mp3”格式。然后什么都对我说。 – Dev
使用mp3的原因是什么?如果从开始我使用.caf文件,它在iPod和iPhone上播放良好,但突然它停止在iPod上播放,但最终在iPhone上播放....这是完全奇怪的,这就是为什么我问这个QSN,如果任何一个也面对这个问题,并得到了解决方案.. –
- 1. QTMovie not playing in new window
- 2. youtube video is not playing in android webview from iframe
- 3. In-app-purchase nib-file?
- 4. input type =“file”alternative in cordova app
- 5. Angular 2:router not in app component
- 6. SoundPool Not Loading in Android App
- 7. shouldAutorotateToInterfaceOrientation not working in universal app
- 8. python code not reading first line in file
- 9. In App Purchase in xamarin.forms
- 10. PrintWriter&File in java
- 11. EXC_BAD_ACCESS in device..not in simulator。(Adwhirl)
- 12. Codeigniter Tank Auth Not Log In In?
- 13. IN NOT IN SQL Server 2005
- 14. LINQ to SQL in and not in
- 15. “=” 和 “IN”/ “NOT IN” 和 “MINUS”
- 16. Go Program in not in WIndows 7
- 17. isset in php not working in angularjs
- 18. @Autowired in bean not in spring context
- 19. App Engine:TypeError in handlers.py
- 20. NOT EXISTS VS NOT IN
- 21. LINQ“not in”not working
- 22. Font not not in DOMPDF
- 23. captcha do not not valid in yii2
- 24. systemProperties in a external file?
- 25. ruby multiline grep in file
- 26. Grep for File in R
- 27. Vim In-File命令
- 28. In App for iOS(Appcelerator)
- 29. jquery sound not playing
- 30. Birt Report not in PDF
我建议你播放mp3格式不要发出给予格式@ himanshu。 – Dev
但这些都是以前玩的。它突然停止播放,即使我没有对代码做任何改变。我的代码是:NSString * any = [ringtonesArray objectAtIndex:indexPath.row]; \t NSString * path = [[NSBundle mainBundle] pathForResource:any ofType:@“caf”]; \t playRingtone = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil]; \t [playRingtone play]; –