|
|
|
@ -67,10 +67,11 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
|
|
|
|
view.addSubview(player) |
|
|
|
player.snp.makeConstraints { (make) in |
|
|
|
make.top.equalTo(self.view).offset(100) |
|
|
|
// make.top.equalTo(self.view).offset(100) |
|
|
|
make.left.right.equalTo(self.view) |
|
|
|
make.height.equalTo(self.view) |
|
|
|
// Note here, the aspect ratio 16:9 priority is lower than 1000 on the line, because the 4S iPhone aspect ratio is not 16:9 |
|
|
|
make.height.equalTo(player.snp.width).multipliedBy(9.0/16.0).priority(750) |
|
|
|
// make.height.equalTo(player.snp.width).multipliedBy(9.0/16.0).priority(750) |
|
|
|
} |
|
|
|
|
|
|
|
player.delegate = self |
|
|
|
@ -82,12 +83,17 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
if let c = currentItem, let url = c.playerURL { |
|
|
|
print(url) |
|
|
|
play(url as URL) |
|
|
|
player.playerLayer!.player!.volume = 0.0 |
|
|
|
|
|
|
|
update() |
|
|
|
} |
|
|
|
updateLoop() |
|
|
|
} |
|
|
|
|
|
|
|
override var prefersStatusBarHidden: Bool { |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
func setItems(items: [MediaItem]) { |
|
|
|
allItems = items |
|
|
|
} |
|
|
|
@ -115,23 +121,79 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func showAlert(title:String, message:String ) { |
|
|
|
|
|
|
|
let alertVC = UIAlertController(title: title, message: message, preferredStyle: .alert) |
|
|
|
|
|
|
|
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) |
|
|
|
alertVC.addAction(okAction) |
|
|
|
|
|
|
|
DispatchQueue.main.async() { () -> Void in |
|
|
|
self.present(alertVC, animated: true, completion: nil) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@objc func favorite(_ sender: AnyObject) { |
|
|
|
print("favorite") |
|
|
|
|
|
|
|
if let c = currentSnapshot { |
|
|
|
do { |
|
|
|
let file = FileHelper.getDocumentsDirectory().appendingPathComponent(c.name) |
|
|
|
VideoHelper.export(item: player.avPlayer!.currentItem!, clipStart: c.time!, clipDuration: c.length!, file: file) { url in |
|
|
|
print(url) |
|
|
|
if (c.loop) { |
|
|
|
let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert) |
|
|
|
|
|
|
|
let oneAction = UIAlertAction(title: "One", style: .default) { (action) in |
|
|
|
self.save(currentSnapshot: c, name: "1") |
|
|
|
} |
|
|
|
let twoAction = UIAlertAction(title: "Two", style: .default) { (action) in |
|
|
|
self.save(currentSnapshot: c, name: "2") |
|
|
|
} |
|
|
|
let threeAction = UIAlertAction(title: "Three", style: .default) { (action) in |
|
|
|
self.save(currentSnapshot: c, name: "3") |
|
|
|
} |
|
|
|
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in |
|
|
|
} |
|
|
|
|
|
|
|
alertController.addAction(oneAction) |
|
|
|
alertController.addAction(twoAction) |
|
|
|
alertController.addAction(threeAction) |
|
|
|
alertController.addAction(cancelAction) |
|
|
|
|
|
|
|
self.present(alertController, animated: true) { |
|
|
|
|
|
|
|
} |
|
|
|
} catch { |
|
|
|
print(error) |
|
|
|
} |
|
|
|
|
|
|
|
// NetworkManager.sharedInstance.currentFav.children.append(currentItem!) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func save(currentSnapshot c: MediaItem, name: String) { |
|
|
|
do { |
|
|
|
try FileHelper.createDir(name: name) |
|
|
|
|
|
|
|
let file = FileHelper.getDocumentsDirectory().appendingPathComponent(name).appendingPathComponent(c.name) |
|
|
|
var dur = loopEnd - loopStart |
|
|
|
if (dur < 0) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
VideoHelper.export(item: player.avPlayer!.currentItem!, clipStart: loopStart, clipDuration: dur, file: file) { url in |
|
|
|
self.showAlert(title: c.name, message: "saved") |
|
|
|
} |
|
|
|
var s = c; |
|
|
|
if (c.type == ItemType.SNAPSHOT && c.parent != nil) { |
|
|
|
s = c.parent! |
|
|
|
} |
|
|
|
|
|
|
|
let jfile = FileHelper.getDocumentsDirectory().appendingPathComponent(name).appendingPathComponent(c.name).appendingPathExtension("json") |
|
|
|
|
|
|
|
let json = s.toJSON() |
|
|
|
print(json) |
|
|
|
try json.write(to: jfile, atomically: true, encoding: .utf8) |
|
|
|
} catch { |
|
|
|
print(error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@objc func startstop(_ sender: AnyObject) { |
|
|
|
if player.isPlaying { |
|
|
|
player.pause() |
|
|
|
@ -169,7 +231,15 @@ print("play") |
|
|
|
|
|
|
|
func updateLoop() { |
|
|
|
if loopOption == 1 { |
|
|
|
loopButton!.title = "cont" |
|
|
|
var dur = loopEnd - loopStart |
|
|
|
|
|
|
|
if dur > 0 { |
|
|
|
loopButton!.title = "(\(dur))" |
|
|
|
} |
|
|
|
else { |
|
|
|
loopButton!.title = "cont" |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
loopButton!.title = "loop" |
|
|
|
@ -187,11 +257,11 @@ print("play") |
|
|
|
player.aspectx = 1.0 |
|
|
|
player.aspecty = 1.0 |
|
|
|
case 2: |
|
|
|
player.aspectx = 0.85 |
|
|
|
player.aspectx = 0.9 |
|
|
|
player.aspecty = 1.0 |
|
|
|
case 3: |
|
|
|
player.aspectx = 1.0 |
|
|
|
player.aspecty = 0.85 |
|
|
|
player.aspecty = 0.9 |
|
|
|
default: |
|
|
|
print("aspect") |
|
|
|
} |
|
|
|
@ -316,9 +386,11 @@ print("finish") |
|
|
|
player.seek(currentItem!.children[0].time!) |
|
|
|
} |
|
|
|
else { |
|
|
|
let duration = player.playerLayer!.playerItem!.duration.seconds |
|
|
|
print(duration) |
|
|
|
player.seek(duration / 2.0) |
|
|
|
let duration = player.playerLayer!.playerItem!.duration |
|
|
|
if !duration.isIndefinite { |
|
|
|
print(duration) |
|
|
|
player.seek(duration.seconds / 2.0) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|