Skip to content

Commit

Permalink
Add video player
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanfei Yu committed Jun 25, 2017
1 parent 49b97ef commit b59816d
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 53 deletions.
6 changes: 3 additions & 3 deletions ASRoam/ASRoam/Class/Follow/Controller/Follow.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.17" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Dnc-si-WGk">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.19" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Dnc-si-WGk">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.16"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -20,7 +20,7 @@
<view key="view" contentMode="scaleToFill" id="9ii-63-am3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="Axg-XQ-RNe"/>
</viewController>
Expand Down
4 changes: 2 additions & 2 deletions ASRoam/ASRoam/Class/Profile/Controller/Profile.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="119.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ataluer_avatar" translatesAutoresizingMaskIntoConstraints="NO" id="wIp-Qq-eCg">
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="avatar" translatesAutoresizingMaskIntoConstraints="NO" id="wIp-Qq-eCg">
<rect key="frame" x="28" y="25" width="70" height="70"/>
<constraints>
<constraint firstAttribute="height" constant="70" id="4mi-Ce-n9w"/>
Expand Down Expand Up @@ -246,7 +246,7 @@
</scene>
</scenes>
<resources>
<image name="ataluer_avatar" width="500" height="500"/>
<image name="avatar" width="800" height="600"/>
<image name="btn_more" width="8" height="14"/>
<image name="home-7" width="30" height="30"/>
<image name="layer-7" width="30" height="30"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ class ProfileController: UIViewController, WKUIDelegate, WKNavigationDelegate, U

if indexPath.section == 1 && indexPath.row == 1 {
self.performSegue(withIdentifier: "ShowVL", sender: nil)

}
}



// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ShowVL" {
Expand Down
114 changes: 89 additions & 25 deletions ASRoam/ASRoam/Class/Profile/Controller/VLCollect/VLController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,85 @@ import BMPlayer
class VLController: UIViewController,UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var videoTable: UITableView!
private var isVerifiedVL = false
var dataSource : Array<String> = []
var netDataSource = ["http://baobab.wdjcdn.com/14525705791193.mp4", "http://baobab.wdjcdn.com/1457162012752491010143.mp4"]
var netDataName = ["风格互换: 原来你我相爱", "周末号外| 中国第一高楼"]

// MARK: - Life Cycle
override func viewDidLoad() {
super.viewDidLoad()


self.isVerifiedVL = false
loadData()
initTable()
showAlert()
}

func loadData() {
let bundle = Bundle.main
//let pathURLs = bundle.urls(forResourcesWithExtension: nil, subdirectory: "Videos")
let paths = bundle.paths(forResourcesOfType: nil, inDirectory: "Videos")
print("##paths: \(String(describing: paths.first)))")
for item in paths {
dataSource.append(item)
}
}

func initTable() {
videoTable.delegate = self
videoTable.dataSource = self
videoTable.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
videoTable.tableFooterView = UIView()
//mineTable.backgroundColor = UIColor.lightGray
}

func showAlert() {
// 1 实例化
let alertVC = UIAlertController(title: "验证后继续", message: nil, preferredStyle: UIAlertControllerStyle.alert)
// 2 带输入框
alertVC.addTextField {
(textField: UITextField!) -> Void in
textField.placeholder = "请输入验证码"
}

// 3 命令(样式:退出Cancel,警告Destructive-按钮标题为红色,默认Default)
let alertActionCancel = UIAlertAction(title: "取消", style: UIAlertActionStyle.destructive, handler: {
action in
self.navigationController?.popViewController(animated: true)
})
let alertActionOK = UIAlertAction(title: "确定", style: UIAlertActionStyle.default, handler: {
action in

let codeField = alertVC.textFields!.first! as UITextField
if codeField.text == "doit" {
self.isVerifiedVL = true
self.videoTable.reloadData()
} else if codeField.text == "my" {
let username = alertVC.textFields!.first! as UITextField
let password = alertVC.textFields!.last! as UITextField
print("##用户名:\(String(describing: username.text)),密码:\(String(describing: password.text))")
} else {

self.navigationController?.popViewController(animated: true)
}
})
alertVC.addAction(alertActionCancel)
alertVC.addAction(alertActionOK)
self.present(alertVC, animated: true, completion: nil)
}


// MARK: - Action
@IBAction func backAction(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}





// MARK: - Table view data source
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
if self.isVerifiedVL == false {
return netDataSource.count
}
return dataSource.count
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
Expand All @@ -48,7 +100,14 @@ class VLController: UIViewController,UITableViewDelegate, UITableViewDataSource
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "VideoCellIdentifier", for: indexPath)

cell.textLabel?.text = "999"
if self.isVerifiedVL == false {
cell.textLabel?.text = netDataName[indexPath.row]
}
else {
cell.textLabel?.text = dataSource[indexPath.row].components(separatedBy: "/").last
print("##\(indexPath.row)")
}

return cell
}

Expand All @@ -57,27 +116,32 @@ class VLController: UIViewController,UITableViewDelegate, UITableViewDataSource
playVideo(indexPath)
}

// MARK: - Navigation

func playVideo(_ indexPath: IndexPath) {
print("555\(indexPath.row)")
// play
//self.perf

self.performSegue(withIdentifier: "pushVPlayer", sender: nil)

print("##555 - \(indexPath.row)")
self.performSegue(withIdentifier: "pushVPlayer", sender: indexPath)
}

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if segue.identifier == "VPController" {
//代码跳转,storyboard中连接了segue,则这里不需要重复调用
let sb = UIStoryboard(name: "Profile", bundle:nil)
let vc = sb.instantiateViewController(withIdentifier: "VPController") as! VLController
//vc
//self.show(vc, sender: nil)
if segue.identifier == "pushVPlayer" {
let indexPath : IndexPath = sender as! IndexPath
print("##performSegue pushVPlayer")
let vpC:VPController = segue.destination as! VPController
vpC.isVerifiedVP = self.isVerifiedVL

if self.isVerifiedVL == true {
vpC.fileURL = dataSource[indexPath.row]
vpC.vTitle = dataSource[indexPath.row].components(separatedBy: "/").last
}
else {
vpC.fileURL = netDataSource[indexPath.row]
vpC.vTitle = netDataName[indexPath.row]
}

// let bundle = Bundle.main
// let pathURL = bundle.path(forResource: "Videos/qidong", ofType: "mp4")
// vpC.fileURL = pathURL
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import UIKit
import BMPlayer

class VPController: UIViewController {


public var isVerifiedVP : Bool?
public var fileURL : String?
public var vTitle : String?
@IBOutlet weak var player: BMCustomPlayer!

override func viewDidLoad() {
Expand All @@ -23,14 +26,15 @@ class VPController: UIViewController {
let _ = self.navigationController?.popViewController(animated: true)
}

// let asset = BMPlayerResource(url: URL(string: "http://baobab.wdjcdn.com/1457162012752491010143.mp4")!,
// name: "周末号外丨中国第一高楼",
// cover: nil,
// subtitle: nil)
let asset = BMPlayerResource(url: URL(string: "http://baobab.wdjcdn.com/1457162012752491010143.mp4")!,
name: "周末号外丨中国第一高楼",
cover: nil,
subtitle: nil)
var urlString : URL!
if self.isVerifiedVP == false {
urlString = URL(string: fileURL!)! as URL
} else {
urlString = URL(fileURLWithPath: fileURL!)
}

print("## video url: \(urlString)")
let asset = BMPlayerResource(url: urlString as URL, name: vTitle!, cover: nil, subtitle: nil)
player.setVideo(resource: asset)
}

Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "avatar.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ASRoam/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ target 'ASRoam' do
pod 'expanding-collection', '~> 1.0.3'
pod 'Alamofire', '~> 4.4'
# pod 'MobilePlayer'
pod 'BMPlayer
pod 'BMPlayer'

end

Expand Down

0 comments on commit b59816d

Please sign in to comment.