Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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
Objective c AVAudioPlayer如何播放快速或慢速文件_Objective C_Iphone_Avaudioplayer - Fatal编程技术网

Objective c AVAudioPlayer如何播放快速或慢速文件

Objective c AVAudioPlayer如何播放快速或慢速文件,objective-c,iphone,avaudioplayer,Objective C,Iphone,Avaudioplayer,我只需要缓慢或快速地听这个文件。任何帮助都将不胜感激AVAudioplayer无法做到这一点,AVPlayer可以做到 // play audio file as NSURL *url; NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] f

我只需要缓慢或快速地听这个文件。任何帮助都将不胜感激

AVAudioplayer无法做到这一点,AVPlayer可以做到

       // play audio file as NSURL *url;
    NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
                                                        forKey:AVURLAssetPreferPreciseDurationAndTimingKey];

    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:options];
    NSString *tracksKey = @"tracks";
    [urlAsset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:
     ^{

         // Completion handler block.
         dispatch_async(dispatch_get_main_queue(),
                        ^{
                            NSError *error = nil;
                            AVKeyValueStatus status = [urlAsset statusOfValueForKey:tracksKey error:&error];

                            if (status == AVKeyValueStatusLoaded) {
                                self.avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
                                [avPlayer play];

                                avPlayer.rate = 0.5;
                            }
                            else {
                                // You should deal with the error appropriately.
                                NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);

                            }

                        });
     }];

AVAudioplayer不能这么做,AVPlayer可以

       // play audio file as NSURL *url;
    NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
                                                        forKey:AVURLAssetPreferPreciseDurationAndTimingKey];

    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:options];
    NSString *tracksKey = @"tracks";
    [urlAsset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:
     ^{

         // Completion handler block.
         dispatch_async(dispatch_get_main_queue(),
                        ^{
                            NSError *error = nil;
                            AVKeyValueStatus status = [urlAsset statusOfValueForKey:tracksKey error:&error];

                            if (status == AVKeyValueStatusLoaded) {
                                self.avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
                                [avPlayer play];

                                avPlayer.rate = 0.5;
                            }
                            else {
                                // You should deal with the error appropriately.
                                NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);

                            }

                        });
     }];

谢谢,但我已经解决了它如下:

安装cocos2d

[[SimpleAudioEngine sharedEngine]播放效果:(NSString*)俯仰(浮动32)平移(浮动32)增益(浮动32)]


它很简单,也很有效

谢谢,但我已经解决了以下问题:

安装cocos2d

[[SimpleAudioEngine sharedEngine]播放效果:(NSString*)俯仰(浮动32)平移(浮动32)增益(浮动32)]


它很简单,也很有效

在Swift 3.0中,它将是这样的-

    audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
    audioP.enableRate = true
    audioP.prepareToPlay()
    audioP.rate = 1.5
    audioP.play()

希望这有帮助:)

在Swift 3.0中,它将是这样的-

    audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
    audioP.enableRate = true
    audioP.prepareToPlay()
    audioP.rate = 1.5
    audioP.play()

希望这有帮助:)

AVPlayer
不能这样做。调整速度时是否希望音频音高保持不变?请检查此
AVPlayer
无法执行此操作。你想在调整速度时音频音高保持不变吗?检查此选项,这会给你带来糟糕的音质。这将给你可怕的音质。