Swift-TableView本地视频无法在实际设备中播放

时间:2016-02-10 16:55:42

标签: ios iphone swift

** swift tableview本地视频没有在实际设备中播放,但是它在模拟器中播放是我使用的代码**

  

我使用AVPlayerViewController播放视频,我使用的格式为mp4,mov,mkv
  **

 import UIKit

  class Videos: NSObject {
    var title: String!
    var url: String!
 }

import UIKit
import AVKit
import AVFoundation

class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var tableDataSource = [Videos]()

override func viewDidLoad() {
    super.viewDidLoad()

    let video1 = Video()
    video1.title1 = "Naplex Exam Introduction "
    video1.url1 = "/Users/maddy/Downloads/AV Player/AV Player/VideOaPP/#1Prescription copy.mov"
    tableDataSource.insert(video1, atIndex: 0)

    let video2 = Videos()
    video2.title2 = "How to Have an Advantage over a Computer Based Exam "
    video2.url2 = "/Users/maddy/Downloads/AV Player/AV Player/VideOaPP/#2Exam.mp4"
    tableDataSource.append(video2)

    let video3 = Video()
    video3.title3 = "How to Answer Math Questions"
    video3.url3 = "/Users/maddy/Downloads/AV Player/AV Player/VideoAPP/#3FollowUp.mp4"
    tableDataSource.append(video3)
    }
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return tableDataSource.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("videoCell", forIndexPath: indexPath) as UITableViewCell

    let video: Videos = tableDataSource[indexPath.row]
    cell.textLabel!.text = videos.title
    return cell
}

// MARK: - Navigation

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showPlayer" {
        if let indexPath = self.tableView.indexPathForSelectedRow {
            let video = tableDataSource[indexPath.row]
            let destination = segue.destinationViewController as! AVPlayerViewController
           // let url = NSURL(string: videos.url)!
            let stringUrl = video.url
            let url = NSURL(fileURLWithPath: stringUrl )
            destination.player = AVPlayer(URL: url)
            destination.player?.play()
        }
    }
}

}

0 个答案:

没有答案