Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NikitaTrophimov

macrumors newbie
Original poster
Apr 29, 2013
3
0
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?

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
 
I see you posted this same question on StackOverflow. You shouldn't cross-post.

Good luck with figuring out the crash.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.