我正在编写一个音频播放器应用程序,使用AVAudio播放器从NSDocs Dir播放mp3,用ALAssetsLibrary子类加载它们。 AVURLAsset当我从tableview中选择一个mp3时,它将推送到播放器&玩,但我正在努力与跳过&以前的按钮 我可以使用下面的代码跳到最后一个轨道,虽然我不确定这是否正确发送一个AVURLAsset来播放而不是队列数组。
Im using apple sample project AVPlayerDemo as the foundation of the ALAssetsLibrary subclass
- (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。