[英]iPhone - issue in playing mp4 video with Swift - iOS
我使用此代碼從資源中准備了mp4文件的路徑並進行播放。
我使用了以下代碼片段:
func playVideo(videoName : String, type: String) {
let url = urlForFile(videoName, fileType: type)
if let url = url {
/* use the scene */
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
player.controlStyle = MPMovieControlStyle.None
player.prepareToPlay()
player.scalingMode = .AspectFill
self.view.addSubview(player.view)
}
println("it started!")
} else {
/* the scene couldn't be intialized */
finishedVideo()
}
}
func urlForFile (fileName : String, fileType: String) -> NSURL? {
let path = NSBundle.mainBundle().pathForResource(fileName, ofType:fileType)
if let path = path {
return NSURL(fileURLWithPath:path)
} else {
return nil
}
}
我用這個函數調用實現它:
playVideo("splash_video", type: "mp4");
該文件在這里:
urlForFile
函數始終返回nil
我也嘗試將視頻轉換為m4v和mov,仍然得到相同的結果“ nil ”
那么我到底可以在SWIFT中播放視頻嗎?
您的代碼看起來正確,沒有任何問題。 您可能忘記了將該文件添加到您的目標成員身份。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.