0

I am currently trying to figure out a way to create a playlist from an array of avplayeritems and save the array to the nssuserdefaults but it wont work.

here is some code

AVAsset *asset = [AVAsset assetWithURL:_videoURL];

AAPLPlayerViewController __weak *weakSelf = self;
NSArray *oldItemsArray = [weakSelf.player items];
AVPlayerItem *newPlayerItem = [AVPlayerItem playerItemWithAsset:asset];
[weakSelf.player insertItem:newPlayerItem afterItem:nil];
[weakSelf queueDidChangeFromArray:oldItemsArray toArray:[self.player items]];

i am trying to create a playlist and store the AVPlayerItems from the queue of the AVQueuePlayer but since it has complex data that includes the AVPlayerItem and AVAsset it will crash when i try to save the [self.player items];

Ive also tried to store it to a Mutable dictionary but no methods ive tried have worked. Can anyone with experience suggest a good method of creating a playlist and storing it for the AVQueuePlayer?

I am using the AVFoundationQueuePlayer Objective C sample from the IOS developer downloads at this link :

https://developer.apple.com/library/ios/samplecode/AVFoundationQueuePlayer-iOS/Introduction/Intro.html#//apple_ref/doc/uid/TP40016104

  • Save the URL, not the asset – matt Aug 08 '16 at 03:32
  • Yes ive tried that i saved the url to favorite to a NSMutable array then saved the array to nsuserdefaults which worked. What i need is the AVQueuePlayer to add all the items from the playlist back to the queue in the viewdidload when the app starts up again.The only way it will let me add items to the queue is one by one which is not what i wanted. i wanted it to save the entire queue into the playlist then when the app opens it adds the playlist back into to queue. – iosdeveloper3773 Aug 08 '16 at 03:42
  • If you don't understand how to use an AVQueuePlayer then that is what you need to ask about. But do not try to save a video asset into user defaults. – matt Aug 08 '16 at 03:51
  • Im able to create a playlist and save it. I just need a way to add the playlist back into the queue. Is there a way find out how many items are in the array then add them all to the queue? – iosdeveloper3773 Aug 08 '16 at 04:04
  • It is so easy to create a queue player with items or to add items to a queue player that I don't even understand what you can be having trouble with. – matt Aug 08 '16 at 04:13
  • the problem is i have to add each item from the array one by one. How can i add all the items from the saved array back into the queue all together at once? – iosdeveloper3773 Aug 08 '16 at 04:24
  • "the problem is i have to add each item from the array one by one" Also known as a _loop_, the most elementary flow control device in all of programming. If you don't know how to loop through an array you really need to stop and learn about that before you try to do _anything_. – matt Aug 08 '16 at 15:36
  • thanks for pointing me to the right place i was able to solve the problem very easily once i understood how to loop through the array. – iosdeveloper3773 Aug 11 '16 at 08:01

0 Answers0