【问题标题】:iphone:-play recorded voice with UILocalNotification soundiphone:-用 UILocalNotification 声音播放录制的声音
【发布时间】:2016-02-17 02:13:06
【问题描述】:

我可以使用 avrecorder 录制语音,但它会将录制的语音保存在文档目录的路径中,我无法找到在 localNotification 声音中使用它的方法,所以请任何人对这个问题有所了解

录制代码:-

-(IBAction)startRecording

{

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err = nil;
    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];

    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [searchPaths objectAtIndex:0];
    NSLog(@"ccc...%@",documentPath);

    if(toggle)
    {
        toggle = NO;

        recordSetting = [[NSMutableDictionary alloc] init];


        [recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];


        strRecordedVoice=[NSString stringWithFormat: @"%.0f.%@", [NSDate timeIntervalSinceReferenceDate] * 1000.0, @"caf"];

        recordedTmpFile = [NSURL fileURLWithPath:[documentPath stringByAppendingPathComponent:strRecordedVoice]];
        NSLog(@"Using Filepath called: %@",recordedTmpFile);
        NSLog(@"Using str: %@",strRecordedVoice);

        recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];





        [recorder setDelegate:self];
                [recorder prepareToRecord];

        [recorder record];

        progressView.progress = 0.0;
        [recorder recordForDuration:(NSTimeInterval) 2];

        lblStatusMsg.text = @"Recording...";
        progressView.progress = 0.0;
        timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(handleTimer) userInfo:nil repeats:YES];



    }
    else
    {
        toggle = YES;

        //Stop the recorder.
        [recorder stop];
    }



}

//本地通知代码

-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{   
    UILocalNotification *notification =[[UILocalNotification alloc]init];

    notification.fireDate=fireDate;
    notification.repeatInterval    = 0;
    notification.alertAction       = NSLocalizedString(@"View", @"View");
notification.soundName = UILocalNotificationDefaultSoundName;

    NSDictionary *userDict = [NSDictionary dictionaryWithObject:ap.strAlarmTitle
                                                         forKey:kRemindMeNotificationDataKey];
    notification.userInfo = userDict;



    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    [notification release];

}


Reference:-you can see it its an alarm application which uses uilocalnotification
    itunes.apple.com/us/app/record-alarm-free/id418511936?mt=8

【问题讨论】:

  • 如何设置一个通知,该通知将使用参数打开您的应用程序,然后播放声音文件?
  • 请您详细说明您的想法...谢谢
  • 这对于 iOS 9 是可能的,请在此处查看我的答案:stackoverflow.com/a/35439941/2051381

标签: iphone ios xcode


【解决方案1】:

您只能将 App Bundle 中的声音用于本地通知

source

【讨论】:

  • 但我已经看到一些应用程序按照我想要的方式进行操作......如果你有想法请告诉我谢谢。
  • 请链接到执行此操作的应用并查看
  • notification.soundName = UILocalNotificationDefaultSoundName;在这里我想用我录制的声音代替 UILocalNotificationDefaultSoundName。
  • 从我链接的文档中很清楚地说:“您可以将应用程序主包中非本地化自定义声音的文件名分配给 soundName 属性”
  • 应用程序“记录警报免费”使用本地通知,但播放默认声音,而不是录制的声音
【解决方案2】:

正如 Martin 所说,您只能使用应用程序包中的声音文件。您提到的“免费录制闹钟”应用也无法将录制的声音播放为通知声音(我已经测试过)。

您可以在本地通知中打开应用后播放声音。

你需要在didReceiveLocalNotification didFinishLaunchingWithOptions

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    [self playSoundWithNotification:notification];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

  if (notification)
  {
      [self playSoundWithNotification:notification];

  }
}

【讨论】:

    【解决方案3】:

    [NSLocalNotification *obj PlaySound];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多