3

aacオーディオファイルで動作するアプリをiOS6に移植していますが、奇妙な動作が見つかりました。(有効な)aacオーディオファイルの期間を取得しようとすると、常に0が返され、iOS4とiOS5では動作します。大丈夫。

¿AvAudioPlayerクラスにdurationプロパティに影響するバグはありますか?currentTimeプロパティに関するいくつかの問題について読みました。

コードは次のとおりです。

NSURL* urlFichero = [NSURL fileURLWithPath:rutaFichero];
avaPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: urlFichero error:nil];
segundos = avaPlayer.duration;
NSLog(@"[ControladorFicheros] Fichero: '%@' Duración: '%f'", nombreFichero, segundos);
[avaPlayer stop];
[avaPlayer release];

ありがとう ;)

4

2 に答える 2

4

最後に、問題は、APIの最新バージョンでは、AVAudioPlayerは、ファイルを再生する準備ができたときにのみ正しい期間のファイルを返すように見えることです。そのため、私の解決策は間違っていました。ファイルの期間を取得する正しい方法です。秒)再現したくない場合は次のようになります。

AVURLAsset *asset = [[[AVURLAsset alloc] initWithURL:anURI_ToResource 
                  options:[NSDictionary dictionaryWithObjectsAndKeys:
                  [NSNumber numberWithBool:YES], 
                  AVURLAssetPreferPreciseDurationAndTimingKey,
                  nil]] autorelease];

 NSTimeInterval durationInSeconds = 0.0;
if (asset) 
     durationInSeconds = CMTimeGetSeconds(asset.duration) ;

迅速

let asset = AVURLAsset(url: url, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true])
let durationInSeconds = CMTimeGetSeconds(asset.duration)
于 2013-03-18T09:17:48.147 に答える
1

同じ問題に気づきました。私の解決策は、代わりに使用することです。

MPMoviePlayerController *testPlayer = [[MPMoviePlayerController alloc] initWithContentURL:filePath];
[testPlater prepareToPlay];
[testPlater play];
于 2013-03-14T04:46:27.083 に答える