How to load NSData into AVPlayerItem?

This is the next question from my post on How to encrypt mp3 files in iOS .

How can I load a track into AVPlayerItem using NSData and not the file path / URL?

thanks

+4
source share
2 answers
[/*name of NSData*/ writeToFile:/*save file path*/ atomically: YES]; NSURL *filepath = [NSURL fileURLWithPath:/*save file path*/]; AVPlayerItem *player = [AVPlayerItem playerItemWithURL:filepath]; 

Unconfirmed, but should work.

+9
source

Update Dustin's answer for Swift 5:

 var audioData: Data // some audio data var fileURL: URL // some local path, probably appending NSTemporaryDirectory() try! audioData.write(to: fileURL) let item = AVPlayerItem(url: fileURL) 
0
source

All Articles