How to Load NSData into an AVPlayerItem?

2019-03-21 14:33发布

问题:

This is a follow-on question from my post about How to Encrypt mp3 Files in iOS.

How would I go about loading a track into an AVPlayerItem using NSData rather than a file path/URL?

Thanks

回答1:

[/*name of NSData*/ writeToFile:/*save file path*/ atomically: YES];
NSURL *filepath = [NSURL fileURLWithPath:/*save file path*/];
AVPlayerItem *player = [AVPlayerItem playerItemWithURL:filepath];

Untested, but should work.