我正在尝试在我的iOS应用程序中播放音频文件.这是我目前的代码
NSString *soundFilePath = [NSString stringWithFormat:@"%@/test.m4a", [[NSBundle mainBundle] resourcePath]];
NSLog(@"%@",soundFilePath);
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[audioPlayer setVolume:1.0];
audioPlayer.delegate = self;
[audioPlayer stop];
[audioPlayer setCurrentTime:0];
[audioPlayer play];
Run Code Online (Sandbox Code Playgroud)
我正在检查一堆其他帖子,但他们通常都做同样的事情.我没有收到错误,但我没有听到模拟器或设备上播放任何音频.
这是我在模拟器上获得音频文件的路径
/Users/username/Library/Application Support/iPhone Simulator/5.1/Applications/long-numbered-thing/BookAdventure.app/test.m4a
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏!
我一直在为iOS 8定制键盘工作一段时间,到目前为止一切都很顺利,但我仍然无法理解这种敲击声音.
我搜索了这个问题的高低,并尝试了几种方法,包括
其中一些在模拟器中工作,但它们都不能在我的设备中工作.任何在点击自定义键盘按钮时成功播放声音的人都可以分享一些工作代码吗?如果代码可以遵守声音设置,那就是最好的.
我已经为我的应用添加了自定义声音,但是当推送到达时它不会被播放.我不知道为什么不,我看不出与我所做的有什么不同,而且涉及的步骤很少.
1)声音文件是可听的有效音频文件(我甚至可以在Xcode中单击并播放它).
2)声音文件出现在应用程序包中:

3)声音文件名在push有效载荷中使用确切的名称和大小写指定:
{"aps":{"alert":"Test","badge":0,"sound":"PyngNotification.caf"}}
Run Code Online (Sandbox Code Playgroud)
4)我已尝试在没有扩展名的情况下指定名称,就像"PyngNotification"一样.
5)推送到达并显示,但不播放自定义声音.
6)无论推送内容是否包含"PyngNotification.caf","default"或""声音,手机都会产生相同的噪音.它是一种短暂的嗡嗡声.
7)手机上没有禁用声音,也没有推送应用程序.
8)该应用程序正在注册UIRemoteNotificationTypeSound(如果是iOS8).(如果通过控制面板查看,应用程序会将声音显示为允许的类型之一).
9)我有多个手机,一个是iOS8,另一个是iOS7.这些声音都没有播放.
10)声音不到30秒.
11)声音是ma4并使用afconvert转换为caf.
我看不到任何我遗漏的步骤,也没有看到任何不正确的步骤.有人有什么想法吗?
我正在努力audio/video call并尝试将来电呼叫notification循环播放1分钟,就像WhatsApp在iOS应用程序是背景时显示,Notification banner隐藏并显示铃声1分钟.
我试过这段代码,它只触发一次:
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString stringWithFormat:@"Video Call from %@",userId];
content.body = @"";
content.userInfo = [userInfo mutableCopy];
content.sound = [UNNotificationSound soundNamed:@""];
NSDate *now = [NSDate date];
now = [now dateByAddingTimeInterval:3];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
[calendar setTimeZone:[NSTimeZone localTimeZone]];
NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone fromDate:now];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO];
UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:@"INCOMING_VOIP_APN" content:content trigger:trigger];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate …Run Code Online (Sandbox Code Playgroud)