Commit 2fa1df59 authored by Alex朱枝文's avatar Alex朱枝文

直播间小窗优化

parent aa871f65
......@@ -24,7 +24,7 @@ class YHBannerModel: SmartCodable {
var live_type: Int = 0 // 播放类型:1 展示最新直播,2指定直播,3 指定录播
var live_pull_url: String = "" //直播拉流链接
var video_url: String = "" //视频链接
var recorded_cate_id: Int = 0 //录播分类ID
var recorded_video_id: Int = 0 //录播分类ID
var app_id: String = "" //声网直播
var token: String = "" //声网直播
var rtmp_channel: String = "" //声网直播
......
......@@ -57,7 +57,10 @@ class YHHomeTabInfoModel : SmartCodable {
class YHHomeLiveInfoModel : SmartCodable {
var id: Int = 0
var status: Int = 0
var pull_url: Int = 0
var app_id: String = ""
var token: String = ""
var rtmp_channel: String = ""
var img_url: String = ""
required init() {
}
}
......@@ -244,7 +244,7 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
// live_type 播放类型:1 展示最新直播,2指定直播,3 指定录播
// live_pull_url 直播拉流链接
// video_url 视频链接
// recorded_cate_id 录播分类id token: String? = nil, channelId
// recorded_video_id 录播id token: String? = nil, channelId
if !checkLogin() {
return
}
......@@ -258,7 +258,7 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
return
}
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.recorded_video_id, url: model.video_url, title: nil, roomId: nil, uid: nil, isLive: false, scene: .fullscreen)
YHPlayerManager.shared.enterVOD(from: cell?.bannerImagV, playbackInfo: playbackInfo)
case 102://图片直播
printLog("跳转录播")
......@@ -316,7 +316,8 @@ extension YHHomeBannerView: FSPagerViewDataSource, FSPagerViewDelegate {
YHPlayerManager.shared.enterBanner(playbackInfo: playbackInfo, inView: cell.bannerImagV)
} else {
let player = YHPlayerManager.shared.getPlayer(.secondary)
player?.setPlayView(nil)
// player?.setPlayView(nil)
player?.clearPlayerView()
}
}
......
......@@ -626,7 +626,7 @@ extension YHJsApi {
let playbackInfo = YHPlayerManager.PlaybackInfo(id: id.intValue(), isLive: true)
YHPlayerManager.shared.enterLive(from: nil, playbackInfo: playbackInfo)
} else if type == 2 {
let playbackInfo = YHPlayerManager.PlaybackInfo(id: id.intValue(), isLive: false)
let playbackInfo = YHPlayerManager.PlaybackInfo(id: id.intValue(), isLive: false, needHideZoomButton: true)
YHPlayerManager.shared.enterVOD(from: nil, playbackInfo: playbackInfo)
}
......
......@@ -184,10 +184,10 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
playbackInfo?.channelId = liveDetail.rtmp_channel
playbackInfo?.token = liveDetail.token
playbackInfo?.title = liveDetail.live_title
messageListView.anchorName = liveDetail.hxNickname
if needJoinLiveChannel {
if !liveDetail.rtmp_channel.isEmpty, !liveDetail.token.isEmpty, let uid = playbackInfo?.uid, let player = player {
player.setPlayView(playerView)
YHPlayerManager.shared.joinChannel(for: player, token: liveDetail.token, channelId: liveDetail.rtmp_channel, uid: uid)
YHPlayerManager.shared.joinChannel(for: player, token: liveDetail.token, channelId: liveDetail.rtmp_channel, uid: uid, view: playerView)
} else if currentPlayingURL == nil, !liveDetail.pullUrl.isEmpty {
play(url: liveDetail.pullUrl) // 如果没有预设URL,使用接口返回的URL播放
}
......@@ -245,7 +245,6 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
func play(url: String, title: String? = nil) {
currentPlayingURL = url
currentVideoTitle = title
// controlView.setTitle(title ?? "")
YHPlayerManager.shared.play(url: url, inView: playerView, title: title)
}
......
......@@ -31,6 +31,7 @@ class YHPlayerManager: NSObject {
let isLive: Bool
var scene: PlaybackScene
var playerType: YHPlayerType
var needHideZoomButton: Bool = false
init(id: Int,
url: String? = nil,
......@@ -40,7 +41,9 @@ class YHPlayerManager: NSObject {
channelId: String? = nil,
uid: UInt? = nil,
isLive: Bool,
scene: PlaybackScene = .fullscreen) {
scene: PlaybackScene = .fullscreen,
playerType: YHPlayerType = .main,
needHideZoomButton: Bool = false) {
self.id = id
self.url = url
self.title = title
......@@ -50,7 +53,8 @@ class YHPlayerManager: NSObject {
self.uid = uid
self.isLive = isLive
self.scene = scene
playerType = .main
self.playerType = playerType
self.needHideZoomButton = needHideZoomButton
}
static func == (lhs: Self, rhs: Self) -> Bool {
......@@ -101,12 +105,9 @@ class YHPlayerManager: NSObject {
// MARK: - Basic Playback Control
func play(url: String, inView view: UIView? = nil, title: String? = nil, type: YHPlayerType = .main) {
func play(url: String, inView view: UIView? = nil, title: String? = nil, type: YHPlayerType = .main, isLive: Bool = false) {
let player = player(for: type)
if let view = view {
player.setPlayView(view)
}
player.play(url: url, title: title, view: view)
player.play(url: url, title: title, view: view, isLive: isLive)
}
func pause(type: YHPlayerType = .main) {
......@@ -121,10 +122,6 @@ class YHPlayerManager: NSObject {
activePlayers[type]?.stop()
}
func setPlayView(_ view: UIView?, type: YHPlayerType = .main) {
activePlayers[type]?.setPlayView(view)
}
func getCurrentPlayer(type: YHPlayerType = .main) -> YHPlayer? {
return activePlayers[type]
}
......@@ -208,13 +205,14 @@ class YHPlayerManager: NSObject {
func joinChannel(for player: YHPlayer,
token: String,
channelId: String,
uid: UInt) {
uid: UInt, view: UIView?) {
let option = AgoraRtcChannelMediaOptions()
option.publishCameraTrack = false
option.publishMicrophoneTrack = false
option.autoSubscribeVideo = true
option.autoSubscribeAudio = true
option.clientRoleType = .audience
player.setPlayModeAndPlayView(.live, view)
if player.type == .secondary {
let connection = AgoraRtcConnection()
connection.channelId = channelId
......@@ -290,13 +288,25 @@ class YHPlayerManager: NSObject {
playerVC.startPosition = startPosition
// 关闭小窗
exitFloating()
var needExitFloating = false
if floatingWindow != nil {
if sourceView != floatingWindow?.contentView {
needExitFloating = false
exitFloating()
} else {
needExitFloating = true
}
}
if let url = playbackInfo.url {
player.play(url: url, title: playbackInfo.title, view: playerVC.playerView)
}
present(navVC, from: sourceView)
if needExitFloating, floatingWindow != nil {
floatingWindow?.dismiss()
floatingWindow = nil
}
}
func enterLive(from sourceView: UIView?, playbackInfo: PlaybackInfo) {
......@@ -323,17 +333,38 @@ class YHPlayerManager: NSObject {
playerVC.playbackInfo = updatedInfo
// 关闭小窗
exitFloating()
var needExitFloating = false
if floatingWindow != nil {
if sourceView != floatingWindow?.contentView {
needExitFloating = false
exitFloating()
} else {
needExitFloating = true
}
}
// 加入频道
if let token = playbackInfo.token,
let channelId = playbackInfo.channelId, let uid = playbackInfo.uid, !token.isEmpty, !channelId.isEmpty {
joinChannel(for: player, token: token, channelId: channelId, uid: uid)
if player.isJoined {
leaveChannel(for: player)
joinChannel(for: player, token: token, channelId: channelId, uid: uid, view: playerVC.playerView)
// // 先清理上次的播放状态
// player.clearPlayerView()
// // 将播放状态转移到floating
// player.setPlayModeAndPlayView(.live, playerVC.playerView)
} else {
joinChannel(for: player, token: token, channelId: channelId, uid: uid, view: playerVC.playerView)
}
} else if let url = playbackInfo.url, url.count > 0 {
player.play(url: url, title: playbackInfo.title, view: playerVC.playerView)
}
present(navVC, from: sourceView)
if needExitFloating, floatingWindow != nil {
floatingWindow?.dismiss()
floatingWindow = nil
}
}
func enterFloating(from viewController: UIViewController? = nil, playbackInfo: PlaybackInfo) {
......@@ -346,14 +377,6 @@ class YHPlayerManager: NSObject {
updatedInfo.scene = .floating
updatedInfo.playerType = playerType
currentPlaybackInfo[playerType] = updatedInfo
// // 加入频道
// if let token = playbackInfo.token,
// let channelId = playbackInfo.channelId, let uid = playbackInfo.uid, !token.isEmpty, !channelId.isEmpty {
// joinChannel(for: player, token: token, channelId: channelId, uid: uid)
// } else if let url = playbackInfo.url, !url.isEmpty {
// player.play(url: url, title: playbackInfo.title)
// }
// 获取当前播放视图的截图和位置
if let sourceView = player.currentPlayView,
......@@ -379,7 +402,17 @@ class YHPlayerManager: NSObject {
if let token = playbackInfo.token,
let channelId = playbackInfo.channelId,
let uid = playbackInfo.uid, !token.isEmpty, !channelId.isEmpty {
joinChannel(for: player, token: token, channelId: channelId, uid: uid)
if player.isJoined {
leaveChannel(for: player)
joinChannel(for: player, token: token, channelId: channelId, uid: uid, view: floatingWindow.contentView)
// // 先清理上次的播放状态
// player.clearPlayerView()
// // 将播放状态转移到floating
// player.setPlayModeAndPlayView(.live, floatingWindow.contentView)
} else {
joinChannel(for: player, token: token, channelId: channelId, uid: uid, view: floatingWindow.contentView)
}
} else if let url = playbackInfo.url, !url.isEmpty {
player.play(url: url, title: playbackInfo.title, view: floatingWindow.contentView)
}
......@@ -391,7 +424,7 @@ class YHPlayerManager: NSObject {
}, completion: { _ in
snapshotView.removeFromSuperview()
floatingWindow.show(in: window)
player.setPlayView(floatingWindow.contentView)
//player.setPlayView(floatingWindow.contentView)
})
}
......@@ -412,14 +445,14 @@ class YHPlayerManager: NSObject {
if let token = playbackInfo.token,
let channelId = playbackInfo.channelId,
let uid = playbackInfo.uid, !token.isEmpty, !channelId.isEmpty {
joinChannel(for: player, token: token, channelId: channelId, uid: uid)
joinChannel(for: player, token: token, channelId: channelId, uid: uid, view: floatingWindow.contentView)
} else if let url = playbackInfo.url, !url.isEmpty {
player.play(url: url, title: playbackInfo.title, view: floatingWindow.contentView)
}
let showFloatingWindow = {
floatingWindow.show(in: window)
player.setPlayView(floatingWindow.contentView)
// player.setPlayView(floatingWindow.contentView)
}
if let viewController = viewController {
......@@ -440,18 +473,22 @@ class YHPlayerManager: NSObject {
currentPlaybackInfo[playerType] = updatedInfo
let player = player(for: playerType)
player.setPlayView(view)
// 加入频道
if let token = playbackInfo.token,
let channelId = playbackInfo.channelId, let uid = playbackInfo.uid, !token.isEmpty, !channelId.isEmpty {
joinChannel(for: player, token: token, channelId: channelId, uid: uid)
joinChannel(for: player, token: token, channelId: channelId, uid: uid, view: view)
} else if let url = playbackInfo.url, !url.isEmpty {
player.play(url: url, title: playbackInfo.title, view: view)
}
}
func exitFloating() {
// 直播退出channel
if floatingWindow?.playbackInfo?.isLive == true, let player = floatingWindow?.player {
leaveChannel(for: player)
} else {
floatingWindow?.player?.stop()
}
floatingWindow?.dismiss()
floatingWindow = nil
}
......@@ -505,7 +542,9 @@ extension YHPlayerManager: AgoraRtcMediaPlayerDelegate {
}
if floatingWindow?.player?.playerKit === playerKit {
floatingWindow?.setVideoSize(videoSize)
DispatchQueue.main.async {
self.floatingWindow?.setVideoSize(videoSize)
}
}
}
}
......
......@@ -42,7 +42,7 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
func play(url: String, title: String? = nil) {
currentPlayingURL = url
currentVideoTitle = title
YHPlayerManager.shared.play(url: url, inView: playerView, title: title)
YHPlayerManager.shared.play(url: url, inView: playerView, title: title, isLive: false)
}
// MARK: - Lifecycle
......@@ -73,6 +73,7 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
topBarView.shareButtonClickEvent = { [weak self] in
self?.shareLive()
}
topBarView.hideZoomButton(playbackInfo?.needHideZoomButton == true)
}
func enterFloating() {
......@@ -142,7 +143,7 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
return
}
let item = detail.recordedVideoSlice[index]
self?.player?.seek(to: item.start_second * 1000)
self?.player?.seek(to: item.start_second * 1000 + 1)
}
// 时间改变回调
progressControl.onTimeChanged = { [weak self] time in
......
......@@ -14,7 +14,7 @@ class YHLiveDetailModel: SmartCodable {
var avatar: String = ""
var hxNickname: String = ""
var hxUid: String = ""
var access_num: Int = 0
var access_num: String = ""
var tips: String = ""
// 1:直播中 2:未直播 0:未知状态 3:结束直播
var status: Int = 0
......
......@@ -12,7 +12,7 @@ import SmartCodable
class YHRecordedDetailModel: SmartCodable {
var account: String = ""
var avatar: String = ""
var access_num: Int = 0
var access_num: String = ""
var tips: String = ""
var recorded_url: String = ""
var recorded_image: String = ""
......
......@@ -62,8 +62,8 @@ class YHLiveMessageCell: UITableViewCell {
}
}
func configureNormalMessage(_ nickname: String, _ content: String) {
let nickAtt = ASAttributedString(string: nickname + ":", .foreground(UIColor.white.withAlphaComponent(0.65)), .font(UIFont.PFSC_R(ofSize: 13)))
func configureNormalMessage(_ nickname: String, _ content: String, isAnchor: Bool) {
let nickAtt = isAnchor ? ASAttributedString(string: nickname + ":", .foreground(UIColor(hexString: "#FFE3BB") ?? UIColor.white), .font(UIFont.PFSC_R(ofSize: 13))) : ASAttributedString(string: nickname + ":", .foreground(UIColor.white.withAlphaComponent(0.65)), .font(UIFont.PFSC_R(ofSize: 13)))
let contentAtt = ASAttributedString(string: content, .foreground(UIColor.white), .font(UIFont.PFSC_R(ofSize: 13)))
contentLabel.attributed.text = nickAtt + contentAtt
}
......
......@@ -11,6 +11,7 @@ import UIKit
class YHLiveMessageListView: UIView {
private var messages: [EMChatMessage] = []
var anchorName: String?
// MARK: - UI Components
......@@ -107,7 +108,8 @@ extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource {
printLog(body.text)
printLog("\(nickName) : \(body.text)")
content = body.text
cell.configureNormalMessage(nickName, content)
let isAnchor = nickName == anchorName
cell.configureNormalMessage(nickName, content, isAnchor: isAnchor)
} else if let body = message.body as? EMCustomMessageBody, body.event == YHChatRoomCustomLocal.tipsEvent, let customExt = body.customExt, let tips = customExt[YHChatRoomCustomLocal.tipsKey] {
cell.configureTipsMessage(tips)
}
......
......@@ -80,7 +80,7 @@ class YHPlayerTopBarView: UIView {
fatalError("init(coder:) has not been implemented")
}
func setupTopBarView(headUrl: String, nickname: String, count: Int) {
func setupTopBarView(headUrl: String, nickname: String, count: String) {
if let url = URL(string: headUrl) {
headPortrait.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
} else {
......@@ -90,9 +90,13 @@ class YHPlayerTopBarView: UIView {
updateCountLabel(count)
}
func updateCountLabel(_ count: Int) {
func updateCountLabel(_ count: String) {
infoCountLabel.text = "\(count)人来过"
}
func hideZoomButton(_ hide: Bool) {
zoomButton.isHidden = hide
}
}
extension YHPlayerTopBarView {
......
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