30天学习Swift项目实战第三天--------本地视频播放器

30天学习Swift项目实战第三天--------本地视频播放器,第1张

概述和之前一样,创建一个新的项目。 再次巩固UITableView的使用。 在Build 里面的Copy Bundle Resources里面添加资源文件 直接上代码: // // ViewController.swift // PlayVideo // // Created by luopan on 16/8/4. // Copyright © 2016年 Hust University. All

和之前一样,创建一个新的项目。 再次巩固UItableVIEw的使用。 在Build 里面的copy Bundle Resources里面添加资源文件 直接上代码: // // VIEwController.swift // PlayVIDeo // // Created by luopan on 16/8/4. // copyright © 2016年 Hust University. All rights reserved. //

import UIKit //导入视频播放的库 import AVKit import AVFoundation

class VIEwController: UIVIEwController,UItableVIEwDataSource,UItableVIEwDelegate {

//展示数据的tableVIEw@IBOutlet weak var vIDeotableVIEw: UItableVIEw!//显示的数据var data = [    vIDeo(image: "vIDeoScreenshot01",Title: "Introduce 3DS Mario",source: "Youtube - 06:32"),vIDeo(image: "vIDeoScreenshot02",Title: "Emoji Among Us",source: "Vimeo - 3:34"),vIDeo(image: "vIDeoScreenshot03",Title: "Seals documentary",source: "Vine - 00:06"),vIDeo(image: "vIDeoScreenshot04",Title: "Adventure Time",source: "Youtube - 02:39"),vIDeo(image: "vIDeoScreenshot05",Title: "Facebook HQ",source: "Facebook - 10:20"),vIDeo(image: "vIDeoScreenshot06",Title: "lijiang Lugu Lake",source: "Allen - 20:30")]//调用系统自带播放器的变量var playVIEwController = AVPlayerVIEwController()var playerVIEw = AVPlayer()overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()        //为自身设置代理    vIDeotableVIEw.dataSource = self    vIDeotableVIEw.delegate = self}//点击播放[@IBAction](http://my.oschina.net/u/866341) func playVIDeobuttonDIDtouch(sender: UIbutton) {    //调用系统播放器    let path = NSBundle.mainBundle().pathForResource("emoji zone",ofType: "mp4")    playerVIEw = AVPlayer(URL: NSURL(fileURLWithPath: path!))    playVIEwController.player = playerVIEw    self.presentVIEwController(playVIEwController,animated: true) {        self.playVIEwController.player?.play()    }}//每一行的高度func tableVIEw(tableVIEw: UItableVIEw,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGfloat {    return 220}//分成两列func numberOfSectionsIntableVIEw(tableVIEw: UItableVIEw) -> Int {    return 2}//每一列的行数func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {    return data.count}//每一行的现实风格func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell {    //解析每一行的cell,并且强制类型转换为 VIDeoCell    let cell = vIDeotableVIEw.dequeueReusableCellWithIDentifIEr("VIDeoCell",forIndexPath: indexPath) as! VIDeoCell    //由于在这里使用的是自定义的cell类,所以需要强制类型转换    //解析得到数据    let vIDeo = data[indexPath.row]        //为每一个控件指定数据    cell.vIDeoScreenshot.image = UIImage(named: vIDeo.image)    cell.vIDeoTitleLabel.text = vIDeo.Title    cell.vIDeoSourceLabel.text = vIDeo.source        return cell}

}

还有一个和UItableVIEwCell绑定的swift文件,如下: // // VIDeoCelltableVIEwCell.swift // PlayVIDeo // // Created by luopan on 16/8/4. // copyright © 2016年 Hust University. All rights reserved. //

import UIKit

struct vIDeo { let image: String let Title: String let source: String }

class VIDeoCell: UItableVIEwCell {

@IBOutlet weak var vIDeoScreenshot: UIImageVIEw!@IBOutlet weak var vIDeoTitleLabel: UILabel!@IBOutlet weak var vIDeoSourceLabel: UILabel!overrIDe func awakeFromNib() {    super.awakeFromNib()    // Initialization code}overrIDe func setSelected(selected: Bool,animated: Bool) {    super.setSelected(selected,animated: animated)    // Configure the vIEw for the selected state}

}

总结

以上是内存溢出为你收集整理的30天学习Swift项目实战第三天--------本地视频播放器全部内容,希望文章能够帮你解决30天学习Swift项目实战第三天--------本地视频播放器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1073394.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存