Commit 8079abe0 authored by Alex朱枝文's avatar Alex朱枝文

增加直播点播入口

parent ce194313
...@@ -273,7 +273,11 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo ...@@ -273,7 +273,11 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//跳转直播 文哥代办 //跳转直播 文哥代办
YHShareAlertView.show(image: "http://gips3.baidu.com/it/u=3886271102,3123389489&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960", title: "12344", subMessage: "12213243", linkUrl: "https://www.baidu.com", isLive: true) guard self.viewModel.liveArr.count > indexPath.row else {
return
}
let item = self.viewModel.liveArr[indexPath.row]
YHPlayerManager.shared.enterLive(from: nil, id: item.id, url: item.pull_url, title: item.live_title, roomId: item.room_id)
} }
} }
......
...@@ -24,8 +24,14 @@ class YHHomeBannerView: UIView { ...@@ -24,8 +24,14 @@ class YHHomeBannerView: UIView {
self.indicatorView.curIndicatorIndex = 0 self.indicatorView.curIndicatorIndex = 0
// 指定显示图片为第一个 // 指定显示图片为第一个
bannerView.selectItem(at: 0, animated: false) bannerView.selectItem(at: 0, animated: false)
let noNeedAutoScroll = dataArr.contains(where: {
$0.skip_type == 100 || $0.skip_type == 102
})
// // TODO: - alex测试
// noNeedAutoScroll = true
// // TODO: - alex测试
// 开启定时器开始滚动 // 开启定时器开始滚动
bannerView.automaticSlidingInterval = bannerSildingInterval bannerView.automaticSlidingInterval = noNeedAutoScroll ? 0 : bannerSildingInterval
bannerView.removesInfiniteLoopForSingleItem = true bannerView.removesInfiniteLoopForSingleItem = true
bannerView.alwaysBounceHorizontal = true bannerView.alwaysBounceHorizontal = true
} }
...@@ -132,6 +138,13 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate { ...@@ -132,6 +138,13 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
if model.isLocalItemFlag { if model.isLocalItemFlag {
return return
} }
// // TODO: - alex测试
// if index == 1 {
// let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell
// YHPlayerManager.shared.enterLive(from: cell?.bannerImagV, id: 23, url: "https://pull-flv-l6.douyincdn.com/stage/stream-116295918585905183.flv?k=e21f1ae1e7591521&t=1733551151&major_anchor_level=common&abr_pts=-800&_session_id=037-202411301359108030CAEAC1F742805E6D.1732946351732.18942&rsi=1", title: nil, roomId: nil, type: .secondary)
// return
// }
// // TODO: - alex测试
if model.skip_url.isEmpty == false { if model.skip_url.isEmpty == false {
switch model.skip_type { switch model.skip_type {
case 1: //跳转H5 case 1: //跳转H5
...@@ -201,6 +214,7 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate { ...@@ -201,6 +214,7 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
vc.url = model.skip_url vc.url = model.skip_url
self.parentViewController?.navigationController?.pushViewController(vc) self.parentViewController?.navigationController?.pushViewController(vc)
case 100:// 直播 case 100:// 直播
//文哥
// media_type 投放类型:1 图片,2 直播 // media_type 投放类型:1 图片,2 直播
// live_id 直播ID // live_id 直播ID
// live_status 直播状态 1:直播中 2:未直播 0:未知状态 3:结束直播 // live_status 直播状态 1:直播中 2:未直播 0:未知状态 3:结束直播
...@@ -208,11 +222,17 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate { ...@@ -208,11 +222,17 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
// live_pull_url 直播拉流链接 // live_pull_url 直播拉流链接
// video_url 视频链接 // video_url 视频链接
// recorded_cate_id 录播分类id // recorded_cate_id 录播分类id
let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell
YHPlayerManager.shared.enterLive(from: cell?.bannerImagV, id: model.live_id, url: model.live_pull_url, title: nil, roomId: nil, type: .secondary)
printLog("跳转直播") printLog("跳转直播")
case 101://录播 case 101://录播
printLog("跳转录播") printLog("跳转录播")
let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell
YHPlayerManager.shared.enterVOD(from: cell?.bannerImagV, id: model.live_id, url: model.video_url, title: nil, type: .secondary)
case 102://图片直播 case 102://图片直播
printLog("跳转录播") printLog("跳转录播")
let cell: YHHomeBannerCollectionViewCell? = pagerView.cellForItem(at: index) as? YHHomeBannerCollectionViewCell
YHPlayerManager.shared.enterLive(from: cell?.bannerImagV, id: model.live_id, url: model.live_pull_url, title: nil, roomId: nil, type: .secondary)
case 0://0 不需要跳转 case 0://0 不需要跳转
printLog("0 不需要跳转") printLog("0 不需要跳转")
default: default:
...@@ -233,4 +253,58 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate { ...@@ -233,4 +253,58 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
func pagerViewDidEndScrollAnimation(_ pagerView: FSPagerView) { func pagerViewDidEndScrollAnimation(_ pagerView: FSPagerView) {
self.indicatorView.curIndicatorIndex = pagerView.currentIndex self.indicatorView.curIndicatorIndex = pagerView.currentIndex
} }
func pagerView(_ pagerView: FSPagerView, willDisplay cell: FSPagerViewCell, forItemAt index: Int) {
if index >= dataArr.count {
return
}
let model = dataArr[index]
if model.isLocalItemFlag {
return
}
// // TODO: - alex测试
// if let cell = cell as? YHHomeBannerCollectionViewCell {
// if index == 1 {
// YHPlayerManager.shared.play(url: "https://pull-flv-l11.douyincdn.com/thirdgame/stream-404525958790382412.flv?expire=1733554587&sign=d1e9f927e20f4a3fb4e2dd2a2712e256&major_anchor_level=common&abr_pts=-800&_session_id=037-20241130145626DBDEB00EB11CB388DD95.1732949787574.66743&rsi=1", inView: cell.bannerImagV, title: nil, type: .secondary)
// } else {
// let player = YHPlayerManager.shared.getPlayer(.secondary)
// player?.setPlayView(nil)
// }
// return
// }
// // TODO: - alex测试
if model.skip_url.isEmpty == false {
if let cell = cell as? YHHomeBannerCollectionViewCell {
if model.skip_type == 100 {
YHPlayerManager.shared.play(url: model.live_pull_url, inView: cell.bannerImagV, title: nil, type: .secondary)
} else {
let player = YHPlayerManager.shared.getPlayer(.secondary)
player?.setPlayView(nil)
}
}
}
}
func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: FSPagerViewCell, forItemAt index: Int) {
if index >= dataArr.count {
return
}
let model = dataArr[index]
if model.isLocalItemFlag {
return
}
// // TODO: - alex测试
// if index == 1 {
// YHPlayerManager.shared.stop(type: .secondary)
// return
// }
// // TODO: - alex测试
if model.skip_url.isEmpty == false {
if model.skip_type == 100 {
YHPlayerManager.shared.stop(type: .secondary)
}
}
}
} }
...@@ -90,7 +90,11 @@ extension YHSelectLookView: UICollectionViewDelegate, UICollectionViewDataSource ...@@ -90,7 +90,11 @@ extension YHSelectLookView: UICollectionViewDelegate, UICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//跳转直播 文哥代办 //跳转直播 文哥代办
guard items.count > indexPath.row else {
return
}
let item = items[indexPath.row]
YHPlayerManager.shared.enterLive(from: nil, id: item.id, url: item.pull_url, title: item.live_title, roomId: item.room_id)
} }
} }
......
...@@ -15,4 +15,16 @@ extension YHLivePlayerViewController { ...@@ -15,4 +15,16 @@ extension YHLivePlayerViewController {
callback(liveDetail, error) callback(liveDetail, error)
} }
} }
func joinLiveRoom(id: Int, callback: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
viewModel.joinLiveRoom(id: id) { success, error in
callback(success, error)
}
}
func leaveLiveRoom(id: Int, callback: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
viewModel.leaveLiveRoom(id: id) { success, error in
callback(success, error)
}
}
} }
...@@ -69,6 +69,9 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -69,6 +69,9 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
setupLiveUI() setupLiveUI()
setupLiveNotifications() setupLiveNotifications()
setupData() setupData()
if YHLoginManager.shared.isLogin() {
joinLiveRoom(id: liveId, callback: { _, _ in })
}
} }
deinit { deinit {
...@@ -95,6 +98,7 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -95,6 +98,7 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
topBarView.closeButtonClickEvent = { [weak self] in topBarView.closeButtonClickEvent = { [weak self] in
self?.quitChatRoom() self?.quitChatRoom()
self?.leaveLiveRoom()
YHPlayerManager.shared.stop(type: .main) YHPlayerManager.shared.stop(type: .main)
if let navigationController = self?.navigationController { if let navigationController = self?.navigationController {
navigationController.popViewController(animated: true) navigationController.popViewController(animated: true)
...@@ -105,6 +109,10 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -105,6 +109,10 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
topBarView.zoomButtonClickEvent = { [weak self] in topBarView.zoomButtonClickEvent = { [weak self] in
self?.enterFloating() self?.enterFloating()
} }
topBarView.shareButtonClickEvent = { [weak self] in
self?.shareLive()
}
} }
private func setupData() { private func setupData() {
...@@ -169,6 +177,9 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -169,6 +177,9 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
name: YHIMHelper.didLogOutEaseIM, name: YHIMHelper.didLogOutEaseIM,
object: nil object: nil
) )
NotificationCenter.default.addObserver(self, selector: #selector(didLoginYH), name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didLogOutYH), name: YhConstant.YhNotification.didLogoutSuccessNotifiction, object: nil)
} }
// MARK: - Public Methods // MARK: - Public Methods
...@@ -207,6 +218,19 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -207,6 +218,19 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
} }
} }
private func leaveLiveRoom() {
guard YHLoginManager.shared.isLogin() else {
return
}
leaveLiveRoom(id: liveId) { _, error in
if let error = error {
printLog("leaveLiveRoom: \(error)")
} else {
printLog("leaveLiveRoom: success")
}
}
}
private func quitChatRoom() { private func quitChatRoom() {
guard let roomId = roomId else { return } guard let roomId = roomId else { return }
...@@ -219,6 +243,13 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -219,6 +243,13 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
} }
} }
private func shareLive() {
guard let liveModel = viewModel.liveDetailModel else {
return
}
YHShareAlertView.show(image: liveModel.live_image, title: "@" + liveModel.account, subMessage: liveModel.live_title, linkUrl: liveModel.live_h5_url, isLive: true)
}
// MARK: - Message Handling // MARK: - Message Handling
private func handleMessageInput(text: String, controller: YHMessageInputViewController) { private func handleMessageInput(text: String, controller: YHMessageInputViewController) {
guard checkLogin(), guard checkLogin(),
...@@ -276,6 +307,16 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -276,6 +307,16 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
appendHistoryMessages(messages) appendHistoryMessages(messages)
} }
@objc private func didLoginYH() {
if YHLoginManager.shared.isLogin() {
joinLiveRoom(id: liveId, callback: { _, _ in })
}
}
@objc private func didLogOutYH() {
//
}
@objc private func didLoginEaseIMSuccess() { @objc private func didLoginEaseIMSuccess() {
if let roomId = roomId { if let roomId = roomId {
joinChatRoom(roomId: roomId) joinChatRoom(roomId: roomId)
......
...@@ -16,11 +16,31 @@ class YHLiveDetailModel: SmartCodable { ...@@ -16,11 +16,31 @@ class YHLiveDetailModel: SmartCodable {
var hxUid: String = "" var hxUid: String = ""
var access_num: Int = 0 var access_num: Int = 0
var tips: String = "" var tips: String = ""
// 1:直播中 2:未直播 0:未知状态 3:结束直播
var status: Int = 0 var status: Int = 0
var roomId: String = "" var roomId: String = ""
var pullUrl: String = "" var pullUrl: String = ""
var goods: [YHLiveGoodsItem] = [] var goods: [YHLiveGoodsItem] = []
// 直播封面
var live_image: String = ""
// 直播主题
var live_title: String = ""
// h5直播地址
var live_h5_url: String = ""
// 预计开始时间
var start_time: String = ""
// 拉流地址360p
var pull_sd1_url: String = ""
// 拉流地址720p
var pull_hd_url: String = ""
// 1:直播中 2:未直播 0:未知状态 3:结束直播
var stream_status: Int = 0
// 实际开始时间
var actual_start_time: String = ""
// 实际结束时间
var actual_end_time: String = ""
required init() { required init() {
} }
} }
......
...@@ -133,4 +133,46 @@ extension YHLiveSalesViewModel { ...@@ -133,4 +133,46 @@ extension YHLiveSalesViewModel {
callback(nil, err) callback(nil, err)
} }
} }
/*
离开直播间
*/
func leaveLiveRoom(id: Int, callback: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.leaveLiveRoom
_ = YHNetRequest.getRequest(url: strUrl, params: ["live_id": id]) { json, _ in
// 1. json字符串 转 对象
printLog("model 是 ==> \(json)")
if json.code == 200 {
callback(true, nil)
} else {
let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg)
callback(false, err)
}
} failBlock: { err in
callback(false, err)
}
}
/*
进入直播间
*/
func joinLiveRoom(id: Int, callback: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.joinLiveRoom
_ = YHNetRequest.getRequest(url: strUrl, params: ["live_id": id]) { json, _ in
// 1. json字符串 转 对象
printLog("model 是 ==> \(json)")
if json.code == 200 {
callback(true, nil)
} else {
let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg)
callback(false, err)
}
} failBlock: { err in
callback(false, err)
}
}
} }
...@@ -676,5 +676,9 @@ class YHAllApiName { ...@@ -676,5 +676,9 @@ class YHAllApiName {
static let categoryList = "super-app/goods/category-list" static let categoryList = "super-app/goods/category-list"
static let goodsList = "super-app/goods/list" static let goodsList = "super-app/goods/list"
// 离开直播间
static let leaveLiveRoom = "super-app/live/app-live-exit"
// 进入直播间--需求登录
static let joinLiveRoom = "super-app/live/app-live-join"
} }
} }
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "live_win_close@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "live_win_close@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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