|
|
@ -36,7 +36,6 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
var downloadDelegate: DownloadDelegate? |
|
|
var downloadDelegate: DownloadDelegate? |
|
|
|
|
|
|
|
|
var loopStart = 0.0 |
|
|
var loopStart = 0.0 |
|
|
var loopEnd = 0.0 |
|
|
|
|
|
|
|
|
|
|
|
var completionHandler: (() -> Void)? |
|
|
var completionHandler: (() -> Void)? |
|
|
|
|
|
|
|
|
@ -56,11 +55,11 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
|
|
|
|
|
var aspect = 1 |
|
|
var aspect = 1 |
|
|
|
|
|
|
|
|
var loopOption = 0 |
|
|
|
|
|
|
|
|
var loopMode = false |
|
|
|
|
|
|
|
|
var thumbnailTime: TimeInterval = 0.0 |
|
|
var thumbnailTime: TimeInterval = 0.0 |
|
|
|
|
|
|
|
|
var edit = true |
|
|
|
|
|
|
|
|
var edit = false |
|
|
var allowEdit = true |
|
|
var allowEdit = true |
|
|
var index = 0 |
|
|
var index = 0 |
|
|
|
|
|
|
|
|
@ -74,7 +73,7 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
barbutton = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(VideoController.captureThumbnail)); |
|
|
barbutton = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(VideoController.captureThumbnail)); |
|
|
navigationItem.rightBarButtonItems = [barbutton!] |
|
|
navigationItem.rightBarButtonItems = [barbutton!] |
|
|
|
|
|
|
|
|
backButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(VideoController.back(_:))) |
|
|
|
|
|
|
|
|
backButton = UIBarButtonItem(title: "0:00", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoController.back(_:))) |
|
|
speedButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoController.speed(_:))) |
|
|
speedButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoController.speed(_:))) |
|
|
loopButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoController.loop(_:))) |
|
|
loopButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoController.loop(_:))) |
|
|
aspectButton = UIBarButtonItem(title:"1", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoController.aspect(_:))) |
|
|
aspectButton = UIBarButtonItem(title:"1", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoController.aspect(_:))) |
|
|
@ -106,16 +105,37 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
|
|
|
|
|
update() |
|
|
update() |
|
|
} |
|
|
} |
|
|
|
|
|
loopMode = detailDelegate!.settings().autoloop |
|
|
updateLoop() |
|
|
updateLoop() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func editItem() { |
|
|
func editItem() { |
|
|
let kv = EditItemView(item: currentSnapshot!) |
|
|
|
|
|
|
|
|
let currentItem = player.playerLayer?.player?.currentItem |
|
|
|
|
|
let totalTime : Double |
|
|
|
|
|
|
|
|
|
|
|
if let playerItem = currentItem { |
|
|
|
|
|
totalTime = TimeInterval(playerItem.duration.value) / TimeInterval(playerItem.duration.timescale) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
totalTime = 1000 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let kv = EditItemView(item: currentSnapshot!, len: totalTime, seek: |
|
|
|
|
|
{ value in |
|
|
|
|
|
print(value) |
|
|
|
|
|
self.player.seekSmoothlyToTime(newChaseTime: value) |
|
|
|
|
|
}, capture: { item in |
|
|
|
|
|
item.scale = Double(self.player.zoom) |
|
|
|
|
|
item.offset = CGPoint(x: self.player.xpos, y: self.player.ypos) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
let pc = UIHostingController(rootView: kv) |
|
|
let pc = UIHostingController(rootView: kv) |
|
|
|
|
|
pc.view.backgroundColor = .clear |
|
|
let navController = UINavigationController(rootViewController: pc) // Creating a navigation controller with pc at the root of the navigation stack. |
|
|
let navController = UINavigationController(rootViewController: pc) // Creating a navigation controller with pc at the root of the navigation stack. |
|
|
// navController.modalPresentationStyle = .fullScreen |
|
|
|
|
|
|
|
|
// navController.modalPresentationStyle = .popover |
|
|
|
|
|
|
|
|
present(navController, animated: false, completion: nil) |
|
|
present(navController, animated: false, completion: nil) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -146,6 +166,8 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
edit = true |
|
|
edit = true |
|
|
|
|
|
loopMode = false |
|
|
|
|
|
updateLoop() |
|
|
reviewButton!.tintColor = UIColor.yellow |
|
|
reviewButton!.tintColor = UIColor.yellow |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -235,7 +257,7 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
file = file.appendingPathExtension("mp4") |
|
|
file = file.appendingPathExtension("mp4") |
|
|
} |
|
|
} |
|
|
print (file) |
|
|
print (file) |
|
|
var dur = loopEnd - loopStart |
|
|
|
|
|
|
|
|
var dur = player.loopEnd - loopStart |
|
|
if (dur < 0) { |
|
|
if (dur < 0) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
@ -278,9 +300,7 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
if player.isPlayToTheEnd { |
|
|
if player.isPlayToTheEnd { |
|
|
player.seek(0, completion: {[weak self] in |
|
|
|
|
|
self!.player.play() |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
player.seekSmoothlyToTime(newChaseTime: 0) |
|
|
player.isPlayToTheEnd = false |
|
|
player.isPlayToTheEnd = false |
|
|
} |
|
|
} |
|
|
player.play() |
|
|
player.play() |
|
|
@ -289,34 +309,22 @@ print("play") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@objc func loop(_ sender: AnyObject) { |
|
|
@objc func loop(_ sender: AnyObject) { |
|
|
loopOption += 1 |
|
|
|
|
|
if loopOption >= 2 { |
|
|
|
|
|
loopOption = 0 |
|
|
|
|
|
|
|
|
if edit { |
|
|
|
|
|
loopMode = false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if loopOption == 1 { |
|
|
|
|
|
let t = player.playerLayer!.player!.currentTime() |
|
|
|
|
|
loopEnd = (Double(t.value) / Double(t.timescale)) - 2.0 |
|
|
|
|
|
|
|
|
else { |
|
|
|
|
|
loopMode = !loopMode |
|
|
} |
|
|
} |
|
|
updateLoop() |
|
|
updateLoop() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func updateLoop() { |
|
|
func updateLoop() { |
|
|
if loopOption == 1 { |
|
|
|
|
|
var dur = loopEnd - loopStart |
|
|
|
|
|
|
|
|
|
|
|
if dur > 0 { |
|
|
|
|
|
loopButton!.title = "(\(dur))" |
|
|
|
|
|
|
|
|
if loopMode { |
|
|
|
|
|
loopButton!.title = "loop" |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
loopButton!.title = "cont" |
|
|
loopButton!.title = "cont" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
loopButton!.title = "loop" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@objc func aspect(_ sender: AnyObject) { |
|
|
@objc func aspect(_ sender: AnyObject) { |
|
|
@ -439,41 +447,51 @@ print("finish") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@objc func thumbnailClicked(_ source: UIButton) { |
|
|
@objc func thumbnailClicked(_ source: UIButton) { |
|
|
currentSnapshot = buttons[source] |
|
|
|
|
|
player.seek(buttons[source]!.time) |
|
|
|
|
|
loopStart = buttons[source]!.time |
|
|
|
|
|
loopOption = 0 |
|
|
|
|
|
loopButton!.title = "loop" |
|
|
|
|
|
|
|
|
if let currentSnapshot = buttons[source] { |
|
|
|
|
|
gotoSnapshot(currentSnapshot: currentSnapshot) |
|
|
|
|
|
|
|
|
if (edit) { |
|
|
if (edit) { |
|
|
// editItem() |
|
|
|
|
|
|
|
|
editItem() |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
// moviePlayer!.currentPlaybackRate = Float(speedOptions[speedOption]) |
|
|
// moviePlayer!.currentPlaybackRate = Float(speedOptions[speedOption]) |
|
|
|
|
|
|
|
|
// print("goto \(buttons[source]!.time!) is \(moviePlayer!.currentPlaybackTime)") |
|
|
// print("goto \(buttons[source]!.time!) is \(moviePlayer!.currentPlaybackTime)") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func gotoSnapshot(currentSnapshot: MediaItem) { |
|
|
|
|
|
player.seekSmoothlyToTime(newChaseTime: currentSnapshot.time) |
|
|
|
|
|
loopStart = currentSnapshot.time |
|
|
|
|
|
player.loopEnd = loopStart + currentSnapshot.length |
|
|
|
|
|
|
|
|
|
|
|
if loopMode && currentSnapshot.scale > 0 { |
|
|
|
|
|
player.zoom = Float(currentSnapshot.scale) |
|
|
|
|
|
player.xpos = currentSnapshot.offset.x |
|
|
|
|
|
player.ypos = currentSnapshot.offset.y |
|
|
|
|
|
player.transformLayer() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.currentSnapshot = currentSnapshot |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@objc func update() { |
|
|
@objc func update() { |
|
|
|
|
|
|
|
|
reviewButton!.title = currentItem!.name |
|
|
reviewButton!.title = currentItem!.name |
|
|
|
|
|
|
|
|
if currentItem!.type == ItemType.SNAPSHOT { |
|
|
if currentItem!.type == ItemType.SNAPSHOT { |
|
|
player.seek(currentItem!.time) |
|
|
player.seek(currentItem!.time) |
|
|
if detailDelegate!.settings().autoloop && currentItem!.loop { |
|
|
|
|
|
loopStart = currentItem!.time |
|
|
loopStart = currentItem!.time |
|
|
loopEnd = currentItem!.time + currentItem!.length |
|
|
|
|
|
loopOption = 1 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
player.loopEnd = currentItem!.time + currentItem!.length |
|
|
currentItem = currentItem!.parent |
|
|
currentItem = currentItem!.parent |
|
|
} else { |
|
|
} else { |
|
|
if !currentItem!.children.isEmpty { |
|
|
if !currentItem!.children.isEmpty { |
|
|
player.seek(currentItem!.children[0].time) |
|
|
|
|
|
|
|
|
player.seekSmoothlyToTime(newChaseTime: currentItem!.children[0].time) |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
let duration = player.playerLayer!.playerItem!.duration |
|
|
let duration = player.playerLayer!.playerItem!.duration |
|
|
if !duration.isIndefinite { |
|
|
if !duration.isIndefinite { |
|
|
print(duration) |
|
|
print(duration) |
|
|
player.seek(duration.seconds / 2.0) |
|
|
|
|
|
|
|
|
player.seekSmoothlyToTime(newChaseTime: duration.seconds / 2.0) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -667,6 +685,61 @@ print("finish") |
|
|
|
|
|
|
|
|
addItemButton(newItem) |
|
|
addItemButton(newItem) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func moveUp() { |
|
|
|
|
|
let t = Date().timeIntervalSince1970 |
|
|
|
|
|
if lastMove + 2 > t { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
lastMove = t |
|
|
|
|
|
|
|
|
|
|
|
if let c = currentItem?.children { |
|
|
|
|
|
if !c.isEmpty{ |
|
|
|
|
|
if let s = currentSnapshot { |
|
|
|
|
|
if var i = c.firstIndex { x in x===s } { |
|
|
|
|
|
print(i) |
|
|
|
|
|
i+=1 |
|
|
|
|
|
if i >= c.count { |
|
|
|
|
|
i = 0 |
|
|
|
|
|
} |
|
|
|
|
|
gotoSnapshot(currentSnapshot: c[i]) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
gotoSnapshot(currentSnapshot: c[0]) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var lastMove = 0.0 |
|
|
|
|
|
|
|
|
|
|
|
func moveDown() { |
|
|
|
|
|
let t = Date().timeIntervalSince1970 |
|
|
|
|
|
if lastMove + 2 > t { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
lastMove = t |
|
|
|
|
|
|
|
|
|
|
|
if let c = currentItem?.children { |
|
|
|
|
|
if !c.isEmpty{ |
|
|
|
|
|
if let s = currentSnapshot { |
|
|
|
|
|
if var i = c.firstIndex { x in x===s } { |
|
|
|
|
|
print(i) |
|
|
|
|
|
i-=1 |
|
|
|
|
|
if i < 0 { |
|
|
|
|
|
i = c.count-1 |
|
|
|
|
|
} |
|
|
|
|
|
gotoSnapshot(currentSnapshot: c[i]) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
gotoSnapshot(currentSnapshot: c[0]) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func bmPlayer(player: BMPlayer) { |
|
|
func bmPlayer(player: BMPlayer) { |
|
|
let speed = Float(speedOptions[speedOption]) |
|
|
let speed = Float(speedOptions[speedOption]) |
|
|
if let pl = player.playerLayer!.player { |
|
|
if let pl = player.playerLayer!.player { |
|
|
@ -684,12 +757,16 @@ print("finish") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func bmPlayer(player: BMPlayer, playTimeDidChange currentTime: TimeInterval, totalTime: TimeInterval) { |
|
|
func bmPlayer(player: BMPlayer, playTimeDidChange currentTime: TimeInterval, totalTime: TimeInterval) { |
|
|
if loopOption == 1 { |
|
|
|
|
|
if currentTime > loopEnd { |
|
|
|
|
|
player.seek(loopStart) |
|
|
|
|
|
|
|
|
if loopMode { |
|
|
|
|
|
if currentTime > player.loopEnd && loopStart < player.loopEnd { |
|
|
|
|
|
player.chaseTime = CMTime.zero |
|
|
|
|
|
player.seekSmoothlyToTime(newChaseTime: loopStart) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if let b = backButton { |
|
|
|
|
|
b.title = BMPlayer.formatSecondsToString(currentTime) |
|
|
} |
|
|
} |
|
|
// print("Time") |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func bmPlayer(player: BMPlayer, playerIsPlaying playing: Bool) { |
|
|
func bmPlayer(player: BMPlayer, playerIsPlaying playing: Bool) { |
|
|
|