2012-05-11 47 views
0

在我的应用程序中,我有一些.caf音频文件(格式:IMA 4:1,立体声,44.100 kHz)。我面临的问题是这些音频文件播放按钮操作(每个铃声一个按钮)。他们在iphone上播放良好(ios版本3到5),但我不能够在iPod上听它。我已经完成了所有声音设置更改,如其他站点上描述的解决方案,但没有任何反应 另外ipod没有卡在耳机模式(这个问题发生在我们插入耳机时,而任何音频文件播放)。所以请尽快给任何解决方案。.caf file in app not playing in iPod

+0

我建议你播放mp3格式不要发出给予格式@ himanshu。 – Dev

+0

但这些都是以前玩的。它突然停止播放,即使我没有对代码做任何改变。我的代码是: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]; –

回答

0

首先您导入,然后框架使用下面的代码:用这种方法

#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。我希望,这也是对你的帮助。

+0

ur和我的代码之间的唯一区别是“audioplayer.volume = 0.5”,这可能是原因,但即使在我的代码中放入音频文件后也不会发声。 –

+0

第一,你必须尝试另一个声音文件,如“.mp3”格式。然后什么都对我说。 – Dev

+0

使用mp3的原因是什么?如果从开始我使用.caf文件,它在iPod和iPhone上播放良好,但突然它停止在iPod上播放,但最终在iPhone上播放....这是完全奇怪的,这就是为什么我问这个QSN,如果任何一个也面对这个问题,并得到了解决方案.. –