我只需要慢慢地或快速地收听文件。任何帮助将不胜感激
答案 0 :(得分:1)
// 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]);
}
});
}];
答案 1 :(得分:1)
谢谢,但我已经解决了以下问题:
安装cocos2d http://www.cocos2d-iphone.org/download
[[SimpleAudioEngine sharedEngine] playEffect:(NSString *)pitch(float32)pan(float32)gain(float32)]
简单而有效......
答案 2 :(得分:0)
audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
audioP.enableRate = true
audioP.prepareToPlay()
audioP.rate = 1.5
audioP.play()
希望这有帮助:)