Commit f3cbeea2 authored by Alex朱枝文's avatar Alex朱枝文

录播slice调整

parent 5484e5d6
...@@ -206,6 +206,14 @@ extension YHLifeViewController { ...@@ -206,6 +206,14 @@ extension YHLifeViewController {
myCollectView.isHidden = !hideFlag myCollectView.isHidden = !hideFlag
noDataView.isHidden = !hideFlag noDataView.isHidden = !hideFlag
} }
func checkLogin()->Bool {
if YHLoginManager.shared.isLogin() == false {
YHOneKeyLoginManager.shared.oneKeyLogin()
return false
}
return true
}
} }
extension YHLifeViewController: UITableViewDelegate, UITableViewDataSource { extension YHLifeViewController: UITableViewDelegate, UITableViewDataSource {
...@@ -276,6 +284,9 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo ...@@ -276,6 +284,9 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo
guard self.viewModel.liveArr.count > indexPath.row else { guard self.viewModel.liveArr.count > indexPath.row else {
return return
} }
if !checkLogin() {
return
}
let item = self.viewModel.liveArr[indexPath.row] let item = self.viewModel.liveArr[indexPath.row]
let playbackInfo = YHPlayerManager.PlaybackInfo(id: item.id, url: item.pull_url, title: item.live_title, roomId: item.room_id, uid: UInt(item.id), isLive: true, scene: .fullscreen) let playbackInfo = YHPlayerManager.PlaybackInfo(id: item.id, url: item.pull_url, title: item.live_title, roomId: item.room_id, uid: UInt(item.id), isLive: true, scene: .fullscreen)
YHPlayerManager.shared.enterLive(from: nil, playbackInfo: playbackInfo) YHPlayerManager.shared.enterLive(from: nil, playbackInfo: playbackInfo)
......
...@@ -111,6 +111,14 @@ private extension YHHomeBannerView { ...@@ -111,6 +111,14 @@ private extension YHHomeBannerView {
} }
} }
} }
func checkLogin()->Bool {
if YHLoginManager.shared.isLogin() == false {
YHOneKeyLoginManager.shared.oneKeyLogin()
return false
}
return true
}
} }
extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate { extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
...@@ -237,17 +245,26 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate { ...@@ -237,17 +245,26 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
// live_pull_url 直播拉流链接 // live_pull_url 直播拉流链接
// video_url 视频链接 // video_url 视频链接
// recorded_cate_id 录播分类id token: String? = nil, channelId // recorded_cate_id 录播分类id token: String? = nil, channelId
if !checkLogin() {
return
}
let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell
let playbackInfo = YHPlayerManager.PlaybackInfo(id: model.live_id, url: model.live_pull_url, title: nil, roomId: nil, token: model.token, channelId: model.rtmp_channel, uid: UInt(model.live_id), isLive: true, scene: .fullscreen) let playbackInfo = YHPlayerManager.PlaybackInfo(id: model.live_id, url: model.live_pull_url, title: nil, roomId: nil, token: model.token, channelId: model.rtmp_channel, uid: UInt(model.live_id), isLive: true, scene: .fullscreen)
YHPlayerManager.shared.enterLive(from: cell?.bannerImagV, playbackInfo: playbackInfo) YHPlayerManager.shared.enterLive(from: cell?.bannerImagV, playbackInfo: playbackInfo)
printLog("跳转直播") printLog("跳转直播")
case 101://录播 case 101://录播
printLog("跳转录播") printLog("跳转录播")
if !checkLogin() {
return
}
let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell
let playbackInfo = YHPlayerManager.PlaybackInfo(id: model.live_id, url: model.video_url, title: nil, roomId: nil, uid: nil, isLive: false, scene: .fullscreen) let playbackInfo = YHPlayerManager.PlaybackInfo(id: model.live_id, url: model.video_url, title: nil, roomId: nil, uid: nil, isLive: false, scene: .fullscreen)
YHPlayerManager.shared.enterVOD(from: cell?.bannerImagV, playbackInfo: playbackInfo) YHPlayerManager.shared.enterVOD(from: cell?.bannerImagV, playbackInfo: playbackInfo)
case 102://图片直播 case 102://图片直播
printLog("跳转录播") printLog("跳转录播")
if !checkLogin() {
return
}
let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell
let playbackInfo = YHPlayerManager.PlaybackInfo(id: model.live_id, url: model.live_pull_url, title: nil, roomId: nil, token: model.token, channelId: model.rtmp_channel, uid: UInt(model.live_id), isLive: true, scene: .fullscreen) let playbackInfo = YHPlayerManager.PlaybackInfo(id: model.live_id, url: model.live_pull_url, title: nil, roomId: nil, token: model.token, channelId: model.rtmp_channel, uid: UInt(model.live_id), isLive: true, scene: .fullscreen)
YHPlayerManager.shared.enterLive(from: cell?.bannerImagV, playbackInfo: playbackInfo) YHPlayerManager.shared.enterLive(from: cell?.bannerImagV, playbackInfo: playbackInfo)
......
...@@ -72,6 +72,14 @@ class YHSelectLookView: UIView { ...@@ -72,6 +72,14 @@ class YHSelectLookView: UIView {
// } // }
} }
func checkLogin()->Bool {
if YHLoginManager.shared.isLogin() == false {
YHOneKeyLoginManager.shared.oneKeyLogin()
return false
}
return true
}
} }
extension YHSelectLookView: UICollectionViewDelegate, UICollectionViewDataSource { extension YHSelectLookView: UICollectionViewDelegate, UICollectionViewDataSource {
...@@ -106,6 +114,9 @@ extension YHSelectLookView: UICollectionViewDelegate, UICollectionViewDataSource ...@@ -106,6 +114,9 @@ extension YHSelectLookView: UICollectionViewDelegate, UICollectionViewDataSource
guard items.count > indexPath.row else { guard items.count > indexPath.row else {
return return
} }
if !checkLogin() {
return
}
let item = items[indexPath.row] let item = items[indexPath.row]
let playbackInfo = YHPlayerManager.PlaybackInfo(id: item.id, url: item.pull_url, title: item.live_title, roomId: item.room_id, uid: UInt(item.id), isLive: true, scene: .fullscreen) let playbackInfo = YHPlayerManager.PlaybackInfo(id: item.id, url: item.pull_url, title: item.live_title, roomId: item.room_id, uid: UInt(item.id), isLive: true, scene: .fullscreen)
YHPlayerManager.shared.enterLive(from: nil, playbackInfo: playbackInfo) YHPlayerManager.shared.enterLive(from: nil, playbackInfo: playbackInfo)
......
...@@ -42,7 +42,6 @@ class YHVODPlayerViewController: YHBasePlayerViewController { ...@@ -42,7 +42,6 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
func play(url: String, title: String? = nil) { func play(url: String, title: String? = nil) {
currentPlayingURL = url currentPlayingURL = url
currentVideoTitle = title currentVideoTitle = title
// controlView.setTitle(title ?? "")
YHPlayerManager.shared.play(url: url, inView: playerView, title: title) YHPlayerManager.shared.play(url: url, inView: playerView, title: title)
} }
...@@ -52,7 +51,6 @@ class YHVODPlayerViewController: YHBasePlayerViewController { ...@@ -52,7 +51,6 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
super.viewDidLoad() super.viewDidLoad()
setupUI() setupUI()
loadVideoDetail() loadVideoDetail()
// controlView.isHidden = true
} }
// MARK: - SetupView // MARK: - SetupView
...@@ -260,7 +258,16 @@ extension YHVODPlayerViewController: YHPlayerDelegate { ...@@ -260,7 +258,16 @@ extension YHVODPlayerViewController: YHPlayerDelegate {
case .opening: case .opening:
printLog("####.opening: \(player.getDuration())") printLog("####.opening: \(player.getDuration())")
case .openCompleted: case .openCompleted:
self.updateProgressControl(player, position: player.getPosition()) let duration = player.getDuration()
self.updateProgressControl(player, position: duration)
if let recordedVideoSlice = self.viewModel.recordedDetailModel?.recordedVideoSlice, recordedVideoSlice.count > 0 {
var marks: [Double] = []
recordedVideoSlice.forEach { item in
marks.append(Double(item.start_second * 1000) / Double(duration))
}
self.progressControl.setupMarkers(marks: marks)
}
printLog("####.openCompleted: \(player.getDuration())") printLog("####.openCompleted: \(player.getDuration())")
case .playing: case .playing:
self.progressControl.setPlaying(true) self.progressControl.setPlaying(true)
...@@ -293,25 +300,28 @@ extension YHVODPlayerViewController: YHPlayerDelegate { ...@@ -293,25 +300,28 @@ extension YHVODPlayerViewController: YHPlayerDelegate {
guard duration > 0 else { return } guard duration > 0 else { return }
var currentIndex: Int? var currentIndex: Int?
if let recordedVideoSlice = viewModel.recordedDetailModel?.recordedVideoSlice, recordedVideoSlice.count > 0 { if let recordedVideoSlice = viewModel.recordedDetailModel?.recordedVideoSlice, recordedVideoSlice.count > 0 {
let lastIndex = recordedVideoSlice.count - 1 currentIndex = recordedVideoSlice.firstIndex(where: { item in
recordedVideoSlice.enumerated().forEach { index, item in return (position >= item.start_second * 1000) && (position <= item.end_second * 1000)
if position >= item.start_second * 1000, position <= item.end_second * 1000 { })
currentIndex = index // let lastIndex = recordedVideoSlice.count - 1
return // recordedVideoSlice.enumerated().forEach { index, item in
} else if index == lastIndex, position >= item.end_second * 1000 { // if position >= item.start_second * 1000, position <= item.end_second * 1000 {
currentIndex = index // currentIndex = index
return // return
} else if position > item.end_second * 1000, index + 1 < lastIndex { // } else if index == lastIndex, position >= item.end_second * 1000 {
let next = recordedVideoSlice[index + 1] // currentIndex = index
if position < next.start_second * 1000 { // return
currentIndex = index // } else if position > item.end_second * 1000, index + 1 < lastIndex {
return // let next = recordedVideoSlice[index + 1]
} // if position < next.start_second * 1000 {
} else if position <= recordedVideoSlice[0].start_second * 1000 { // currentIndex = index
currentIndex = 0 // return
return // }
} // } else if position <= recordedVideoSlice[0].start_second * 1000 {
} // currentIndex = 0
// return
// }
// }
} }
progressControl.updateTime(Double(position) / 1000.0, duration: Double(duration) / 1000.0, currentIndex: currentIndex) progressControl.updateTime(Double(position) / 1000.0, duration: Double(duration) / 1000.0, currentIndex: currentIndex)
} }
......
...@@ -82,9 +82,18 @@ class YHVideoProgressControl: UIView { ...@@ -82,9 +82,18 @@ class YHVideoProgressControl: UIView {
return view return view
}() }()
private lazy var markersContainer: UIView = {
let view = UIView()
view.isUserInteractionEnabled = false // 确保不影响滑块的交互
return view
}()
private var markers: [UIView] = []
private var lastRatios: [Double] = []
// MARK: - Properties // MARK: - Properties
private var segments: [String] = [] private var segments: [String] = []
private var currentSegmentIndex = 0 private var currentSegmentIndex: Int? = nil
private var isPlaying = false private var isPlaying = false
private var currentTime: TimeInterval = 0 private var currentTime: TimeInterval = 0
private var duration: TimeInterval = 0 private var duration: TimeInterval = 0
...@@ -109,6 +118,7 @@ class YHVideoProgressControl: UIView { ...@@ -109,6 +118,7 @@ class YHVideoProgressControl: UIView {
addSubview(bottomVisualEffectView) addSubview(bottomVisualEffectView)
addSubview(segmentCollection) addSubview(segmentCollection)
addSubview(progressSlider) addSubview(progressSlider)
addSubview(markersContainer)
addSubview(playButton) addSubview(playButton)
addSubview(currentTimeLabel) addSubview(currentTimeLabel)
addSubview(timeSeparator) addSubview(timeSeparator)
...@@ -139,6 +149,10 @@ class YHVideoProgressControl: UIView { ...@@ -139,6 +149,10 @@ class YHVideoProgressControl: UIView {
make.top.equalTo(segmentCollection.snp.bottom).offset(8) make.top.equalTo(segmentCollection.snp.bottom).offset(8)
} }
markersContainer.snp.makeConstraints { make in
make.edges.equalTo(progressSlider)
}
playButton.contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8) playButton.contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
playButton.snp.makeConstraints { make in playButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(8) make.left.equalToSuperview().offset(8)
...@@ -176,19 +190,67 @@ class YHVideoProgressControl: UIView { ...@@ -176,19 +190,67 @@ class YHVideoProgressControl: UIView {
segmentCollection.reloadData() segmentCollection.reloadData()
} }
/// 计算为0-1的比例值
func setupMarkers(marks: [Double]) {
guard marks != lastRatios else {
return
}
lastRatios = marks
// 清除现有的标记
markers.forEach { $0.removeFromSuperview() }
markers.removeAll()
// 计算间距
// 使用 slider 的实际宽度
let totalWidth = progressSlider.bounds.width // 使用 slider 的宽度
let trackRect = progressSlider.trackRect(forBounds: progressSlider.bounds)
let thumbWidth = progressSlider.thumbRect(forBounds: progressSlider.bounds,
trackRect: trackRect,
value: 0).width
let usableWidth = totalWidth - thumbWidth
// 创建新的标记点
for item in marks {
let marker = UIView()
marker.backgroundColor = .white
markersContainer.addSubview(marker)
markers.append(marker)
let x = (usableWidth * item) + thumbWidth/2
marker.snp.makeConstraints { make in
make.centerX.equalTo(progressSlider).offset(x - totalWidth/2)
make.centerY.equalToSuperview()
make.width.equalTo(1)
make.height.equalTo(2)
}
}
}
func updateTime(_ current: TimeInterval, duration: TimeInterval, currentIndex: Int? = nil) { func updateTime(_ current: TimeInterval, duration: TimeInterval, currentIndex: Int? = nil) {
self.currentTime = current self.currentTime = current
self.duration = duration self.duration = duration
progressSlider.value = Float(current / duration) progressSlider.value = Float(current / duration)
currentTimeLabel.text = String(format: "%02d:%02d", Int(current) / 60, Int(current) % 60) currentTimeLabel.text = String(format: "%02d:%02d", Int(current) / 60, Int(current) % 60)
totalTimeLabel.text = String(format: "%02d:%02d", Int(duration) / 60, Int(duration) % 60) totalTimeLabel.text = String(format: "%02d:%02d", Int(duration) / 60, Int(duration) % 60)
if let currentIndex = currentIndex, currentIndex != currentSegmentIndex { if currentIndex != currentSegmentIndex {
currentSegmentIndex = currentIndex currentSegmentIndex = currentIndex
if segmentCollection.numberOfSections > 0, segmentCollection.numberOfItems(inSection: 0) > currentIndex { if let currentIndex = currentIndex {
segmentCollection.scrollToItem(at: IndexPath(item: currentIndex, section: 0), at: .centeredHorizontally, animated: true) if segmentCollection.numberOfSections > 0, segmentCollection.numberOfItems(inSection: 0) > currentIndex {
segmentCollection.scrollToItem(at: IndexPath(item: currentIndex, section: 0), at: .centeredHorizontally, animated: true)
segmentCollection.reloadData()
}
} else {
segmentCollection.reloadData() segmentCollection.reloadData()
} }
} }
// if let currentIndex = currentIndex, currentIndex != currentSegmentIndex {
// currentSegmentIndex = currentIndex
// if segmentCollection.numberOfSections > 0, segmentCollection.numberOfItems(inSection: 0) > currentIndex {
// if currentIndex > 0 {
// segmentCollection.scrollToItem(at: IndexPath(item: currentIndex, section: 0), at: .centeredHorizontally, animated: true)
// }
// segmentCollection.reloadData()
// }
// }
} }
func setPlaying(_ playing: Bool) { func setPlaying(_ playing: Bool) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment