How to Load NSData into an AVPlayerItem?

前端 未结 2 1949
挽巷
挽巷 2021-02-10 12:16

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 fil

相关标签:
2条回答
  • 2021-02-10 12:36

    Updating 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 讨论(0)
  • 2021-02-10 12:58
    [/*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.

    0 讨论(0)
提交回复
热议问题