iPhone simulator plays video, real device won't

前端 未结 4 612
伪装坚强ぢ
伪装坚强ぢ 2021-01-22 10:00

I am building an app in Swift on Xcode 7.2

I added a video to my ViewController. Here\'s the code:

import UIKit
import AVKit
import AVFoundation

class G         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-22 10:43

    Because your path you was using is from simulator, on real device it changed. if you added this file to your project, you can get this url via:

    func getDocumentsURL() -> NSURL {
        let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
        return documentsURL
    }
    
    func fileInDocumentsDirectory(filename: String) -> String {
    
        let fileURL = getDocumentsURL().URLByAppendingPathComponent(filename)
        return fileURL.path!
    
    }
    

提交回复
热议问题