Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在调用录音机后播放声音,然后比动画开始播放声音?_Iphone_Animation_Avaudioplayer_Avaudiorecorder - Fatal编程技术网

Iphone 如何在调用录音机后播放声音,然后比动画开始播放声音?

Iphone 如何在调用录音机后播放声音,然后比动画开始播放声音?,iphone,animation,avaudioplayer,avaudiorecorder,Iphone,Animation,Avaudioplayer,Avaudiorecorder,我的任务是开发一个应用程序,在用户吹灭蜡烛后播放声音,而不是应该播放的声音。对于吹蜡烛,我使用了一个音频录像机,它可以捕捉用户吹蜡烛,然后启动停止蜡烛的动画,然后开始播放歌曲,但不播放歌曲。我已在本地存储歌曲。(在我的应用程序中) 用于音频录像机 NSURL *url1 = [NSURL fileURLWithPath:@"/dev/null"]; NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKe

我的任务是开发一个应用程序,在用户吹灭蜡烛后播放声音,而不是应该播放的声音。对于吹蜡烛,我使用了一个音频录像机,它可以捕捉用户吹蜡烛,然后启动停止蜡烛的动画,然后开始播放歌曲,但不播放歌曲。我已在本地存储歌曲。(在我的应用程序中)

用于音频录像机

    NSURL *url1 = [NSURL fileURLWithPath:@"/dev/null"];

    NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
        [NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
        [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
        [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
        [NSNumber numberWithInt: AVAudioQualityMax],  AVEncoderAudioQualityKey,
        nil];
    NSError *error1;

    recorder = [[AVAudioRecorder alloc] initWithURL:url1 settings:settings error:&error1];
动画图像开始播放,然后播放歌曲

imageView1.animationImages= [NSArray arrayWithObjects:
    [UIImage imageNamed:@"can6.png"],
    [UIImage imageNamed:@"can7.png"],
    [UIImage imageNamed:@"can8.png"],
    [UIImage imageNamed:@"can9.png"],
    [UIImage imageNamed:@"can10.png"],nil];
    [imageView1 setAnimationRepeatCount:1];
    imageView1.animationDuration=0.7;
    [imageView1 startAnimating];
    [recorder stop];
    player = [[AVAudioPlayer alloc] 
              initWithContentsOfURL:[NSURL fileURLWithPath:
             [[NSBundle mainBundle] pathForResource:xyz song ofType:nil]]
             error:nil];
    NSLog(@"music play-%@",xyz song);
    [player prepareToPlay];
    [player play];
所有代码均正常工作,只有声音未播放。
我得到蜡烛停止动画开始,但我不能在这里的歌曲。虽然上面的声音播放代码在另一个视图中工作得很好,它可以播放歌曲,但它不能在这里播放歌曲。请帮助我。

检查[[NSBundle mainBundle]pathForResource:xyz song of type:nil]的结果是否为nil。我认为问题可能是类型超过零。例如,如果您的歌曲是HappyBirthday.mp3,您应该拨打

[[NSBundle mainBundle] pathForResource:@"HappyBirthday" ofType:@"mp3"];

我试过这样做,但效果并不理想。我对xyz歌曲的意思是它是一种NSString*xyz歌曲正如我所说,播放器(与播放器代码相同)将在另一个视图中完美播放,我不调用录制器和动画。