我正在编写一个音频播放器应用程序,使用 AVAudio Player 从 NSDocs Dir 播放 mp3,使用 ALAssetsLibrary 子类和 AVURLAsset 加载它们可以使用以下代码跳到最后一首曲目,尽管我不确定这是否是发送一个 AVURLAsset 播放而不是队列数组的正确方法。
我使用苹果示例项目 AVPlayerDemo 作为 ALAssetsLibrary 子类的基础
- (IBAction)nextButtonTapped:(id)sender {
NSArray *sourceitems = [[finalSources objectAtIndex:_selectedPath.section] items];
[sourceitems enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
id next = nil;
next = [next objectAtIndex:_selectedPath.row];
if (idx + 1 < sourceitems.count) {
next = [sourceitems objectAtIndex:idx + 1];
AssetBrowserItem *item = next;
AVURLAsset *asset = (AVURLAsset*)item.asset;
[self setURL:asset.URL];
NSLog(@"next %@", next);
//here it continues to the last object and plays,
//but i just want to skip one track and play, then click again and move
//to the next one
}
}];
}
- (void)setURL:(NSURL*)URL
{
if (mURL != URL)
{
mURL = [URL copy];
/*
Create an asset for inspection of a resource referenced by a given URL.
Load the values for the asset keys "tracks", "playable".
*/
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:mURL options:nil];
NSArray *requestedKeys = [NSArray arrayWithObjects:kTracksKey, kPlayableKey, nil];
/* Tells the asset to load the values of any of the specified keys that are not already loaded. */
[asset loadValuesAsynchronouslyForKeys:requestedKeys completionHandler:
^{
dispatch_async( dispatch_get_main_queue(),
^{
/* IMPORTANT: Must dispatch to main queue in order to operate on the AVPlayer and AVPlayerItem. */
[self prepareToPlayAsset:asset withKeys:requestedKeys];
[self syncLabels:mURL];
});
}];
}
}
任何指针将不胜感激。
在此先感谢 Gav。