|
|
@ -27,7 +27,7 @@ protocol ItemController { |
|
|
|
|
|
|
|
|
// Trimmer: https://github.com/Tomohiro-Yamashita/VideoTimelineView |
|
|
// Trimmer: https://github.com/Tomohiro-Yamashita/VideoTimelineView |
|
|
|
|
|
|
|
|
class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
|
|
|
|
|
class VideoController: UIViewController, ItemController, BMPlayerDelegate, EditItemDelegate { |
|
|
var player = BMPlayer() |
|
|
var player = BMPlayer() |
|
|
var currentItem: MediaItem? |
|
|
var currentItem: MediaItem? |
|
|
var currentSnapshot: MediaItem? |
|
|
var currentSnapshot: MediaItem? |
|
|
@ -120,14 +120,11 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
totalTime = 1000 |
|
|
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) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
if (currentSnapshot!.length < 0.001) { |
|
|
|
|
|
setEnd() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let kv = EditItemView(item: currentSnapshot!, len: totalTime, delegate: self) |
|
|
|
|
|
|
|
|
let pc = UIHostingController(rootView: kv) |
|
|
let pc = UIHostingController(rootView: kv) |
|
|
pc.view.backgroundColor = .clear |
|
|
pc.view.backgroundColor = .clear |
|
|
@ -138,6 +135,41 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func captureZoom() { |
|
|
|
|
|
if let item = currentSnapshot { |
|
|
|
|
|
item.scale = Double(self.player.zoom) |
|
|
|
|
|
item.offset = CGPoint(x: self.player.xpos, y: self.player.ypos) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setStart() { |
|
|
|
|
|
if let item = currentSnapshot { |
|
|
|
|
|
let ctime = currentTime() |
|
|
|
|
|
|
|
|
|
|
|
item.time = ctime |
|
|
|
|
|
|
|
|
|
|
|
item.objectWillChange.send() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func currentTime() -> Double { |
|
|
|
|
|
CMTimeGetSeconds(player.playerLayer!.playerItem!.currentTime()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setEnd() { |
|
|
|
|
|
if let item = currentSnapshot { |
|
|
|
|
|
let ctime = currentTime() |
|
|
|
|
|
|
|
|
|
|
|
if (ctime > item.time) { |
|
|
|
|
|
item.length = ctime - item.time |
|
|
|
|
|
item.objectWillChange.send() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func seek(_ value: Double) { |
|
|
|
|
|
self.player.seekSmoothlyToTime(newChaseTime: value) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
override var prefersStatusBarHidden: Bool { |
|
|
override var prefersStatusBarHidden: Bool { |
|
|
return true |
|
|
return true |
|
|
@ -407,11 +439,6 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func playerItemDidReachEnd(_ note: Notification) { |
|
|
|
|
|
print("finish") |
|
|
|
|
|
// Timer.scheduledTimer(timeInterval: 0.6, target: self, selector: #selector(update), userInfo: nil, repeats: false) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func addItemButton(_ newItem: MediaItem) { |
|
|
func addItemButton(_ newItem: MediaItem) { |
|
|
let frame = CGRect(x: 0, y: 0, width: 66.0, height: 44.0); |
|
|
let frame = CGRect(x: 0, y: 0, width: 66.0, height: 44.0); |
|
|
@ -448,19 +475,18 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
|
|
|
|
|
|
@objc func thumbnailClicked(_ source: UIButton) { |
|
|
@objc func thumbnailClicked(_ source: UIButton) { |
|
|
if let currentSnapshot = buttons[source] { |
|
|
if let currentSnapshot = buttons[source] { |
|
|
gotoSnapshot(currentSnapshot: currentSnapshot) |
|
|
|
|
|
|
|
|
|
|
|
if (edit) { |
|
|
if (edit) { |
|
|
|
|
|
self.currentSnapshot = currentSnapshot |
|
|
editItem() |
|
|
editItem() |
|
|
} |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
gotoSnapshot(currentSnapshot: currentSnapshot) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
// moviePlayer!.currentPlaybackRate = Float(speedOptions[speedOption]) |
|
|
|
|
|
|
|
|
|
|
|
// print("goto \(buttons[source]!.time!) is \(moviePlayer!.currentPlaybackTime)") |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private func gotoSnapshot(currentSnapshot: MediaItem) { |
|
|
private func gotoSnapshot(currentSnapshot: MediaItem) { |
|
|
player.seekSmoothlyToTime(newChaseTime: currentSnapshot.time) |
|
|
|
|
|
|
|
|
player.forceSeekSmoothlyToTime(newChaseTime: currentSnapshot.time) |
|
|
loopStart = currentSnapshot.time |
|
|
loopStart = currentSnapshot.time |
|
|
player.loopEnd = loopStart + currentSnapshot.length |
|
|
player.loopEnd = loopStart + currentSnapshot.length |
|
|
|
|
|
|
|
|
@ -475,7 +501,6 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@objc func update() { |
|
|
@objc func update() { |
|
|
|
|
|
|
|
|
reviewButton!.title = currentItem!.name |
|
|
reviewButton!.title = currentItem!.name |
|
|
|
|
|
|
|
|
if currentItem!.type == ItemType.SNAPSHOT { |
|
|
if currentItem!.type == ItemType.SNAPSHOT { |
|
|
@ -503,24 +528,6 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
player.play() |
|
|
player.play() |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func enteredFullscreen() { |
|
|
|
|
|
// let mp = UIApplication.shared.keyWindow; |
|
|
|
|
|
// if let moviePlayerContainer = mp!.recursiveSearchForViewWithName("MPVideoContainerView") { |
|
|
|
|
|
// if (moviePlayerContainer.gestureRecognizers != nil) { |
|
|
|
|
|
// return; |
|
|
|
|
|
// } |
|
|
|
|
|
// installGestures(moviePlayerContainer) |
|
|
|
|
|
// } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func exitedFullscreen() { |
|
|
|
|
|
// moviePlayer!.view.removeFromSuperview(); |
|
|
|
|
|
// moviePlayer = nil; |
|
|
|
|
|
// NotificationCenter.default.removeObserver(self); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func installGestures(_ moviePlayer: UIView) { |
|
|
func installGestures(_ moviePlayer: UIView) { |
|
|
@ -759,8 +766,7 @@ class VideoController: UIViewController, ItemController, BMPlayerDelegate { |
|
|
func bmPlayer(player: BMPlayer, playTimeDidChange currentTime: TimeInterval, totalTime: TimeInterval) { |
|
|
func bmPlayer(player: BMPlayer, playTimeDidChange currentTime: TimeInterval, totalTime: TimeInterval) { |
|
|
if loopMode { |
|
|
if loopMode { |
|
|
if currentTime > player.loopEnd && loopStart < player.loopEnd { |
|
|
if currentTime > player.loopEnd && loopStart < player.loopEnd { |
|
|
player.chaseTime = CMTime.zero |
|
|
|
|
|
player.seekSmoothlyToTime(newChaseTime: loopStart) |
|
|
|
|
|
|
|
|
player.forceSeekSmoothlyToTime(newChaseTime: loopStart) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|