我想将 uislider 添加到我的播放器中,以便我可以在 AVPlayer 中播放音频时实现擦洗。一旦第一首歌曲播放完,uislider 将回到原来的位置,下一首歌曲将开始播放。如果有人帮助我,我将不胜感激。这是我的代码。
-(IBAction)goToiPodLibrary:(UIButton *)sender
{
// Create picker view
MPMediaPickerController* picker = [[MPMediaPickerController alloc] init];
picker.delegate = self;
if (userMediaItemCollection) {
MusicTableViewController *controller = [[MusicTableViewController alloc] initWithNibName: @"MusicTableView" bundle: nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController: controller animated: YES];
// else, if no music is chosen yet, display the media item picker
} else {
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (@"Add songs to play", "Prompt in media item picker");
// The media item picker uses the default UI style, so it needs a default-style
// status bar to match it visually
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated: YES];
[self presentModalViewController: picker animated: YES];
}
}
-(IBAction)playButtonPressed:(UIButton *)sender
{
[myPlayer play];
}
-(IBAction)pauseButtonPressed:(UIButton *)sender
{
[myPlayer pause];
}
-(void) mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
// Dismiss selection view
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void) mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
// Dismiss selection view
[self dismissViewControllerAnimated:YES completion:nil];
// Get AVAsset
NSURL* assetUrl = [mediaItemCollection.representativeItem valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:assetUrl options:nil];
// Create player item
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithAsset:asset];
// Play it
myPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[playlistSongsArray addObjectsFromArray:mediaItemCollection.items];
NSLog(@" Playlist songs %@",playlistSongsArray);
[self.myPlaylistTable reloadData];
[myPlayer play];
}