AVPlayer でオーディオを再生しながらスクラブを実装できるように、プレーヤーに uislider を追加したいと考えています。最初の曲が再生されるとすぐに、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];
}