修复bug,播放跳转到指定秒
This commit is contained in:
parent
b78bd95996
commit
e0e727573a
@ -109,3 +109,30 @@ extension UIView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MARK: -------------- 添加点击事件 --------------
|
||||||
|
extension UIView {
|
||||||
|
|
||||||
|
private var sp_tapGestureBlock: ((_ view: UIView) -> Void)? {
|
||||||
|
get {
|
||||||
|
return objc_getAssociatedObject(self,&AssociatedKeys.sp_tapGesture) as? ((_ view: UIView) -> Void)
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
objc_setAssociatedObject(self,&AssociatedKeys.sp_tapGesture, newValue, .OBJC_ASSOCIATION_COPY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sp_addTapGestureRecognizer(_ block: ((_ view: UIView) -> Void)?) {
|
||||||
|
if sp_tapGestureBlock == nil {
|
||||||
|
let tap = UITapGestureRecognizer(target: self, action: #selector(handleTapGestureRecognizer(tap:)))
|
||||||
|
self.addGestureRecognizer(tap)
|
||||||
|
}
|
||||||
|
self.sp_tapGestureBlock = block
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func handleTapGestureRecognizer(tap: UITapGestureRecognizer) {
|
||||||
|
if tap.state == .recognized {
|
||||||
|
self.sp_tapGestureBlock?(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -24,7 +24,7 @@ class SPLoginViewController: SPViewController {
|
|||||||
private lazy var stackView: UIStackView = {
|
private lazy var stackView: UIStackView = {
|
||||||
let stackView = UIStackView(arrangedSubviews: [faceBookButton, appleButton])
|
let stackView = UIStackView(arrangedSubviews: [faceBookButton, appleButton])
|
||||||
stackView.axis = .vertical
|
stackView.axis = .vertical
|
||||||
stackView.spacing = 18
|
stackView.spacing = 20
|
||||||
return stackView
|
return stackView
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -146,6 +146,7 @@ extension SPLoginViewController {
|
|||||||
logoImageView.snp.makeConstraints { make in
|
logoImageView.snp.makeConstraints { make in
|
||||||
make.centerX.equalToSuperview()
|
make.centerX.equalToSuperview()
|
||||||
make.top.equalToSuperview().offset(kSPStatusbarHeight + kSPMainW(120))
|
make.top.equalToSuperview().offset(kSPStatusbarHeight + kSPMainW(120))
|
||||||
|
make.width.height.equalTo(120)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nameImageView.snp.makeConstraints { make in
|
// nameImageView.snp.makeConstraints { make in
|
||||||
@ -156,7 +157,7 @@ extension SPLoginViewController {
|
|||||||
stackView.snp.makeConstraints { make in
|
stackView.snp.makeConstraints { make in
|
||||||
make.left.equalToSuperview().offset(37)
|
make.left.equalToSuperview().offset(37)
|
||||||
make.centerX.equalToSuperview()
|
make.centerX.equalToSuperview()
|
||||||
make.top.equalTo(logoImageView.snp.bottom).offset(40)
|
make.top.equalTo(logoImageView.snp.bottom).offset(80)
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = agreementLabel.textLayout?.textBoundingSize ?? .zero
|
let size = agreementLabel.textLayout?.textBoundingSize ?? .zero
|
||||||
|
@ -152,7 +152,7 @@ extension SPMineViewController {
|
|||||||
}
|
}
|
||||||
///获取播放记录
|
///获取播放记录
|
||||||
private func requestPlayHistoryList() {
|
private func requestPlayHistoryList() {
|
||||||
SPVideoAPI.requestPlayHistoryList(page: 1, pageSize: 3) { [weak self] listModel in
|
SPVideoAPI.requestPlayHistoryList(page: 1, pageSize: 10) { [weak self] listModel in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
if let list = listModel?.list {
|
if let list = listModel?.list {
|
||||||
self.headerView.playHistoryArr = list
|
self.headerView.playHistoryArr = list
|
||||||
|
@ -15,6 +15,11 @@ class SPAboutUsHeaderView: UIView {
|
|||||||
imageView.layer.cornerRadius = 8
|
imageView.layer.cornerRadius = 8
|
||||||
imageView.layer.masksToBounds = true
|
imageView.layer.masksToBounds = true
|
||||||
imageView.backgroundColor = .red
|
imageView.backgroundColor = .red
|
||||||
|
imageView.isUserInteractionEnabled = true
|
||||||
|
imageView.sp_addTapGestureRecognizer { _ in
|
||||||
|
guard let url = URL(string: SPWebBaseURL) else { return }
|
||||||
|
UIApplication.shared.open(url)
|
||||||
|
}
|
||||||
return imageView
|
return imageView
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ class SPMinePlayHistoryView: UIView {
|
|||||||
layout.minimumLineSpacing = 8
|
layout.minimumLineSpacing = 8
|
||||||
layout.minimumInteritemSpacing = 8
|
layout.minimumInteritemSpacing = 8
|
||||||
layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16)
|
layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16)
|
||||||
|
layout.scrollDirection = .horizontal
|
||||||
return layout
|
return layout
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ class SPMinePlayHistoryView: UIView {
|
|||||||
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
||||||
collectionView.delegate = self
|
collectionView.delegate = self
|
||||||
collectionView.dataSource = self
|
collectionView.dataSource = self
|
||||||
collectionView.isScrollEnabled = false
|
collectionView.showsHorizontalScrollIndicator = false
|
||||||
SPMinePlayHistoryCell.registerCell(collectionView: collectionView)
|
SPMinePlayHistoryCell.registerCell(collectionView: collectionView)
|
||||||
return collectionView
|
return collectionView
|
||||||
}()
|
}()
|
||||||
|
@ -10,7 +10,11 @@ import UIKit
|
|||||||
class SPMineWalletView: UIView {
|
class SPMineWalletView: UIView {
|
||||||
|
|
||||||
override var intrinsicContentSize: CGSize {
|
override var intrinsicContentSize: CGSize {
|
||||||
return .init(width: kSPScreenWidth, height: 119)
|
if isShowMore {
|
||||||
|
return .init(width: kSPScreenWidth, height: 119)
|
||||||
|
} else {
|
||||||
|
return .init(width: kSPScreenWidth, height: 82)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var userInfo: SPUserInfo? {
|
var userInfo: SPUserInfo? {
|
||||||
@ -20,6 +24,16 @@ class SPMineWalletView: UIView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///是否展示更多按钮
|
||||||
|
var isShowMore: Bool = true {
|
||||||
|
didSet {
|
||||||
|
moreButton.isHidden = !isShowMore
|
||||||
|
lineView.isHidden = !isShowMore
|
||||||
|
|
||||||
|
invalidateIntrinsicContentSize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//MARK: UI属性
|
//MARK: UI属性
|
||||||
private lazy var bgView: UIView = {
|
private lazy var bgView: UIView = {
|
||||||
let view = UIView()
|
let view = UIView()
|
||||||
|
@ -85,7 +85,12 @@ class SPPlayerDetailViewController: SPPlayerListViewController {
|
|||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
self.navigationController?.setNavigationBarHidden(true, animated: true)
|
self.navigationController?.setNavigationBarHidden(true, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillDisappear(_ animated: Bool) {
|
||||||
|
super.viewWillDisappear(animated)
|
||||||
|
|
||||||
|
self.uploadPlayTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func play() {
|
override func play() {
|
||||||
@ -110,28 +115,27 @@ class SPPlayerDetailViewController: SPPlayerListViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func currentPlayFinish() {
|
override func currentPlayFinish() {
|
||||||
if let videoInfo = self.viewModel.currentPlayer?.videoInfo, let activityId = self.activityId {
|
if let videoInfo = self.viewModel.currentPlayer?.videoInfo, let activityId = self.activityId, let shortPlayId = videoInfo.short_play_id, let videoId = videoInfo.short_play_video_id {
|
||||||
//播放完成统计
|
//播放完成统计
|
||||||
SPVideoAPI.requestViewingFinish(shortPlayId: videoInfo.short_play_id ?? "", videoId: videoInfo.short_play_video_id ?? "", activityId: activityId)
|
SPVideoAPI.requestViewingFinish(shortPlayId: shortPlayId, videoId: videoId, activityId: activityId)
|
||||||
|
//播放完成上报进度为0
|
||||||
|
SPVideoAPI.requestUploadPlayTime(shortPlayId: shortPlayId, videoId: videoId, seconds: 0)
|
||||||
}
|
}
|
||||||
super.currentPlayFinish()
|
super.currentPlayFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func currentPlayTimeDidChange(time: Int) {
|
override func currentPlayTimeDidChange(time: Int) {
|
||||||
super.currentPlayTimeDidChange(time: time)
|
super.currentPlayTimeDidChange(time: time)
|
||||||
let videoInfo = self.viewModel.currentPlayer?.videoInfo
|
|
||||||
|
|
||||||
|
|
||||||
//每播放5秒上报一次 播放时长小于上次上报时间也需要上报
|
//每播放5秒上报一次 播放时长小于上次上报时间也需要上报
|
||||||
if (time >= lastUploadTime + 5 || time < lastUploadTime) && time >= 5 {
|
// if (time >= lastUploadTime + 5 || time < lastUploadTime) && time >= 5 {
|
||||||
lastUploadTime = time
|
// lastUploadTime = time
|
||||||
|
//
|
||||||
guard let shortPlayId = videoInfo?.short_play_id, let videoId = videoInfo?.short_play_video_id else { return }
|
// uploadPlayTime()
|
||||||
//上报播放时长
|
// }
|
||||||
SPVideoAPI.requestUploadPlayTime(shortPlayId: shortPlayId, videoId: videoId, seconds: time)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,6 +241,23 @@ extension SPPlayerDetailViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///上报播放进度
|
||||||
|
private func uploadPlayTime() {
|
||||||
|
let videoInfo = self.viewModel.currentPlayer?.videoInfo
|
||||||
|
let currentTime = self.viewModel.currentPlayer?.currentPosition ?? 0
|
||||||
|
let duration = self.viewModel.currentPlayer?.duration ?? 0
|
||||||
|
|
||||||
|
var time = currentTime
|
||||||
|
if currentTime >= duration {
|
||||||
|
time = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let shortPlayId = videoInfo?.short_play_id, let videoId = videoInfo?.short_play_video_id else { return }
|
||||||
|
//上报播放时长
|
||||||
|
SPVideoAPI.requestUploadPlayTime(shortPlayId: shortPlayId, videoId: videoId, seconds: time * 1000)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func buyVipFinishNotification() {
|
@objc private func buyVipFinishNotification() {
|
||||||
guard SPLoginManager.manager.userInfo?.is_vip == true else { return }
|
guard SPLoginManager.manager.userInfo?.is_vip == true else { return }
|
||||||
|
|
||||||
@ -254,6 +275,7 @@ extension SPPlayerDetailViewController {
|
|||||||
self.requestDetailData()
|
self.requestDetailData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK: -------------- SPPlayerListViewControllerDataSource --------------
|
//MARK: -------------- SPPlayerListViewControllerDataSource --------------
|
||||||
@ -289,12 +311,20 @@ extension SPPlayerDetailViewController: SPPlayerListViewControllerDataSource, SP
|
|||||||
self.episodeView?.currentIndex = indexPath.row
|
self.episodeView?.currentIndex = indexPath.row
|
||||||
let videoInfo = detailModel?.episodeList?[indexPath.row]
|
let videoInfo = detailModel?.episodeList?[indexPath.row]
|
||||||
|
|
||||||
// titleLabel.text = String(format: "kPlayerDetailTitleString".localized, "\(videoInfo?.episode ?? "0")", self.detailModel?.shortPlayInfo?.name ?? "")
|
|
||||||
titleLabel.text = detailModel?.shortPlayInfo?.name
|
titleLabel.text = detailModel?.shortPlayInfo?.name
|
||||||
episodeLabel.text = "\(videoInfo?.episode ?? "0")/\(detailModel?.shortPlayInfo?.episode_total ?? 0)"
|
episodeLabel.text = "\(videoInfo?.episode ?? "0")/\(detailModel?.shortPlayInfo?.episode_total ?? 0)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MARK: -------------- APP生命周期 --------------
|
||||||
|
extension SPPlayerDetailViewController {
|
||||||
|
|
||||||
|
@objc override func willResignActiveNotification() {
|
||||||
|
super.willResignActiveNotification()
|
||||||
|
uploadPlayTime()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extension SPPlayerDetailViewController {
|
extension SPPlayerDetailViewController {
|
||||||
|
|
||||||
@ -316,7 +346,11 @@ extension SPPlayerDetailViewController {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if let row = row {
|
if let row = row {
|
||||||
self.scrollToItem(indexPath: IndexPath(row: row, section: 0), animated: false)
|
self.scrollToItem(indexPath: IndexPath(row: row, section: 0), animated: false) { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
//跳转到指定进度
|
||||||
|
self.viewModel.currentPlayer?.seekToTime(toTime: (videoInfo.play_seconds ?? 0) / 1000)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.play()
|
self.play()
|
||||||
}
|
}
|
||||||
@ -324,23 +358,6 @@ extension SPPlayerDetailViewController {
|
|||||||
} else {
|
} else {
|
||||||
self.play()
|
self.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if let playHistoryModel = self.playHistoryModel {
|
|
||||||
var row: Int?
|
|
||||||
self.detailModel?.episodeList?.enumerated().forEach({
|
|
||||||
if $1.episode == playHistoryModel.current_episode {
|
|
||||||
row = $0
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if let row = row {
|
|
||||||
self.scrollToItem(indexPath: IndexPath(row: row, section: 0), animated: false)
|
|
||||||
}
|
|
||||||
self.playHistoryModel = nil
|
|
||||||
} else {
|
|
||||||
self.play()
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ class SPPlayerListViewController: SPViewController {
|
|||||||
return self.collectionView(self.collectionView, numberOfItemsInSection: 0)
|
return self.collectionView(self.collectionView, numberOfItemsInSection: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func scrollToItem(indexPath: IndexPath, animated: Bool = true) {
|
func scrollToItem(indexPath: IndexPath, animated: Bool = true, completer: (() -> Void)? = nil) {
|
||||||
CATransaction.setCompletionBlock { [weak self] in
|
CATransaction.setCompletionBlock { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
if !animated {
|
if !animated {
|
||||||
@ -212,6 +212,7 @@ class SPPlayerListViewController: SPViewController {
|
|||||||
self.play()
|
self.play()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
completer?()
|
||||||
}
|
}
|
||||||
CATransaction.begin()
|
CATransaction.begin()
|
||||||
self.collectionView.scrollToItem(at: indexPath, at: .top, animated: animated);
|
self.collectionView.scrollToItem(at: indexPath, at: .top, animated: animated);
|
||||||
|
@ -25,5 +25,7 @@ class SPVideoInfoModel: SPModel, SmartCodable {
|
|||||||
var short_play_id: String?
|
var short_play_id: String?
|
||||||
var short_play_video_id: String?
|
var short_play_video_id: String?
|
||||||
var video_url: String?
|
var video_url: String?
|
||||||
|
///播放进度,毫秒
|
||||||
|
var play_seconds: Int?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class SPWalletViewController: SPViewController {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
private lazy var headerView: SPWalletHeaderView = {
|
private lazy var headerView: SPWalletHeaderView = {
|
||||||
let view = SPWalletHeaderView(frame: .init(x: 0, y: 0, width: kSPScreenWidth, height: 152))
|
let view = SPWalletHeaderView(frame: .init(x: 0, y: 0, width: kSPScreenWidth, height: 115))
|
||||||
view.userInfo = SPLoginManager.manager.userInfo
|
view.userInfo = SPLoginManager.manager.userInfo
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
@ -18,6 +18,7 @@ class SPWalletHeaderView: UIView {
|
|||||||
//MARK: UI属性
|
//MARK: UI属性
|
||||||
private lazy var contentView: SPMineWalletView = {
|
private lazy var contentView: SPMineWalletView = {
|
||||||
let view = SPMineWalletView()
|
let view = SPMineWalletView()
|
||||||
|
view.isShowMore = false
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 140 KiB |
Loading…
x
Reference in New Issue
Block a user