Why does the following sample code that uses AVQueuePlayer crashes randomly on the certain songs, but works ok on the others? What am i doing wrong?
If you'll run this code, you'll notice that it could crashed on the first try or on the second. Or maybe later...
I've got the following call stack and description in Xcode:
https://imageshack.us/a/img826/8466/crashd.png
Code:
// ViewController.h
#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property AVPlayerItem *playerItem;
@property AVQueuePlayer *queuePlayer;
- (IBAction)buttonPressed:(id)sender;
- (void)checkStatus;
@end
Code:
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize playerItem = _playerItem;
@synthesize queuePlayer = _queuePlayer;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)buttonPressed:(id)sender
{
self.playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://cs5107.vk.me/u46779903/audios/34ba1ede2b0e.mp3"]];
NSArray *playerItemsArray = [NSArray arrayWithObject:self.playerItem];
if (!self.queuePlayer)
{
self.queuePlayer = [AVQueuePlayer queuePlayerWithItems:playerItemsArray];
}
else
{
[self.queuePlayer insertItem:self.playerItem afterItem:nil];
[self.queuePlayer advanceToNextItem];
}
[self.queuePlayer play];
}
@end
If you'll run this code, you'll notice that it could crashed on the first try or on the second. Or maybe later...
I've got the following call stack and description in Xcode:
https://imageshack.us/a/img826/8466/crashd.png