Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
2fa1df59
Commit
2fa1df59
authored
Dec 05, 2024
by
Alex朱枝文
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
直播间小窗优化
parent
aa871f65
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
225 additions
and
147 deletions
+225
-147
YHBannerModel.swift
galaxy/galaxy/Classes/Modules/Home(首页)/M/YHBannerModel.swift
+1
-1
YHConfigModel.swift
galaxy/galaxy/Classes/Modules/Home(首页)/M/YHConfigModel.swift
+4
-1
YHHomeBannerView.swift
.../galaxy/Classes/Modules/Home(首页)/V/YHHomeBannerView.swift
+4
-3
YHJsApi.swift
...galaxy/Classes/Modules/InteractionH5(与H5交互)/YHJsApi.swift
+1
-1
YHLivePlayerViewController.swift
.../LivestreamSales(直播销售)/C/YHLivePlayerViewController.swift
+2
-3
YHPlayer.swift
...xy/Classes/Modules/LivestreamSales(直播销售)/C/YHPlayer.swift
+127
-98
YHPlayerManager.swift
...ses/Modules/LivestreamSales(直播销售)/C/YHPlayerManager.swift
+70
-31
YHVODPlayerViewController.swift
...s/LivestreamSales(直播销售)/C/YHVODPlayerViewController.swift
+3
-2
YHLiveDetailModel.swift
...s/Modules/LivestreamSales(直播销售)/M/YHLiveDetailModel.swift
+1
-1
YHRecordedDetailModel.swift
...dules/LivestreamSales(直播销售)/M/YHRecordedDetailModel.swift
+1
-1
YHLiveMessageCell.swift
...s/Modules/LivestreamSales(直播销售)/V/YHLiveMessageCell.swift
+2
-2
YHLiveMessageListView.swift
...dules/LivestreamSales(直播销售)/V/YHLiveMessageListView.swift
+3
-1
YHPlayerTopBarView.swift
.../Modules/LivestreamSales(直播销售)/V/YHPlayerTopBarView.swift
+6
-2
No files found.
galaxy/galaxy/Classes/Modules/Home(首页)/M/YHBannerModel.swift
View file @
2fa1df59
...
...
@@ -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
=
""
//声网直播
...
...
galaxy/galaxy/Classes/Modules/Home(首页)/M/YHConfigModel.swift
View file @
2fa1df59
...
...
@@ -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
()
{
}
}
galaxy/galaxy/Classes/Modules/Home(首页)/V/YHHomeBannerView.swift
View file @
2fa1df59
...
...
@@ -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
()
}
}
...
...
galaxy/galaxy/Classes/Modules/InteractionH5(与H5交互)/YHJsApi.swift
View file @
2fa1df59
...
...
@@ -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
)
}
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/C/YHLivePlayerViewController.swift
View file @
2fa1df59
...
...
@@ -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
)
}
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/C/YHPlayer.swift
View file @
2fa1df59
...
...
@@ -15,6 +15,12 @@ enum YHPlayerType {
case
secondary
}
// MARK: - 播放模式
enum
YHPlayMode
{
case
live
// 直播
case
vod
// 点播
}
protocol
YHPlayerDelegate
:
AnyObject
{
func
player
(
_
player
:
YHPlayer
,
didChangedToState
state
:
AgoraMediaPlayerState
,
reason
:
AgoraMediaPlayerReason
)
func
player
(
_
player
:
YHPlayer
,
didChangedToPosition
position
:
Int
)
...
...
@@ -24,13 +30,7 @@ protocol YHPlayerDelegate: AnyObject {
// MARK: - 播放器实例封装
class
YHPlayer
{
// 持有一个固定的播放视图
private
lazy
var
playerContentView
:
UIView
=
{
let
view
=
UIView
()
view
.
backgroundColor
=
.
black
return
view
}()
// MARK: - Properties
weak
var
delegate
:
YHPlayerDelegate
?
let
type
:
YHPlayerType
var
playerKit
:
AgoraRtcMediaPlayerProtocol
?
...
...
@@ -43,15 +43,17 @@ class YHPlayer {
private(set)
var
currentToken
:
String
?
private(set)
var
currentUid
:
UInt
?
private(set)
var
isJoined
:
Bool
=
false
private(set)
var
playMode
:
YHPlayMode
=
.
vod
// 保存最后的播放信息用于恢复
private
var
lastPlaybackInfo
:
(
url
:
String
?,
title
:
String
?
)?
//private var lastPlaybackInfo: (url: String?, title: String?, mode: YHPlayMode
)?
var
isMuted
:
Bool
{
get
{
playerKit
?
.
getMute
()
??
false
}
set
{
playerKit
?
.
mute
(
newValue
)
}
}
// MARK: - Initialization
init
(
type
:
YHPlayerType
,
playerKit
:
AgoraRtcMediaPlayerProtocol
?,
agoraKit
:
AgoraRtcEngineKit
?)
{
self
.
type
=
type
self
.
playerKit
=
playerKit
...
...
@@ -60,51 +62,59 @@ class YHPlayer {
playerKit
?
.
setLoopCount
(
-
1
)
}
// func setPlayViewNull() {
// let hideVideoCanvas = AgoraRtcVideoCanvas()
// hideVideoCanvas.uid = currentUid ?? 0
// hideVideoCanvas.view = nil
// hideVideoCanvas.renderMode = .hidden
// agoraKit?.setupRemoteVideo(hideVideoCanvas)
// }
func
setPlayView
(
_
view
:
UIView
?)
{
// 保存旧的视图用于动画
// let oldView = currentPlayView
// 设置新的视图
// MARK: - View Management
func
setPlayModeAndPlayView
(
_
mode
:
YHPlayMode
,
_
view
:
UIView
?)
{
playMode
=
mode
currentPlayView
=
view
playerKit
?
.
setRenderMode
(
.
fit
)
// if let view = view, let uid = currentUid, let channelId = currentChannelId {
// if type == .secondary {
// // 副播放器需要使用 Ex 方法
// let videoCanvas = AgoraRtcVideoCanvas()
// videoCanvas.view = view
// videoCanvas.renderMode = .fit
// videoCanvas.uid = uid
// let connection = AgoraRtcConnection()
// connection.channelId = channelId
// connection.localUid = uid
// agoraKit?.setupRemoteVideoEx(videoCanvas, connection: connection)
// } else {
// let hideVideoCanvas = AgoraRtcVideoCanvas()
// hideVideoCanvas.uid = uid
// hideVideoCanvas.view = nil
// hideVideoCanvas.renderMode = .hidden
// agoraKit?.setupRemoteVideo(hideVideoCanvas)
// DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
// // 主播放器使用普通方法
// let videoCanvas = AgoraRtcVideoCanvas()
// videoCanvas.view = view
// videoCanvas.renderMode = .fit
// videoCanvas.uid = uid
// self.agoraKit?.setupRemoteVideo(videoCanvas)
// })
//
// }
// }
if
playMode
==
.
vod
{
// 点播模式:直接设置 MediaPlayer 的视图
playerKit
?
.
setView
(
view
)
}
else
{
// 直播模式:设置远程视图
if
let
view
=
view
,
let
uid
=
currentUid
{
setupRemoteVideo
(
view
:
view
,
uid
:
uid
)
}
}
}
func
clearPlayerView
()
{
currentPlayView
=
nil
if
playMode
==
.
vod
{
playerKit
?
.
setView
(
nil
)
}
else
{
// 直播模式:设置远程视图
if
let
uid
=
currentUid
{
setupRemoteVideo
(
view
:
nil
,
uid
:
uid
)
}
}
}
private
func
setupRemoteVideo
(
view
:
UIView
?,
uid
:
UInt
)
{
if
type
==
.
secondary
{
// 副播放器使用 Ex 方法
guard
let
channelId
=
currentChannelId
else
{
return
}
let
videoCanvas
=
AgoraRtcVideoCanvas
()
videoCanvas
.
view
=
view
videoCanvas
.
renderMode
=
.
fit
videoCanvas
.
uid
=
uid
let
connection
=
AgoraRtcConnection
()
connection
.
channelId
=
channelId
connection
.
localUid
=
uid
agoraKit
?
.
setupRemoteVideoEx
(
videoCanvas
,
connection
:
connection
)
}
else
{
// 主播放器使用普通方法
let
videoCanvas
=
AgoraRtcVideoCanvas
()
videoCanvas
.
view
=
view
videoCanvas
.
renderMode
=
.
fit
videoCanvas
.
uid
=
uid
agoraKit
?
.
setupRemoteVideo
(
videoCanvas
)
}
}
// MARK: - Channel Management
func
setJoinInfo
(
token
:
String
,
channelId
:
String
,
uid
:
UInt
)
{
currentToken
=
token
currentChannelId
=
channelId
...
...
@@ -113,6 +123,24 @@ class YHPlayer {
}
func
clearJoinInfo
()
{
if
let
uid
=
currentUid
{
// 清除远程视图
let
videoCanvas
=
AgoraRtcVideoCanvas
()
videoCanvas
.
uid
=
uid
videoCanvas
.
view
=
nil
videoCanvas
.
renderMode
=
.
hidden
if
type
==
.
secondary
{
guard
let
channelId
=
currentChannelId
else
{
return
}
let
connection
=
AgoraRtcConnection
()
connection
.
channelId
=
channelId
connection
.
localUid
=
uid
agoraKit
?
.
setupRemoteVideoEx
(
videoCanvas
,
connection
:
connection
)
}
else
{
agoraKit
?
.
setupRemoteVideo
(
videoCanvas
)
}
}
currentToken
=
nil
currentChannelId
=
nil
currentUid
=
nil
...
...
@@ -122,70 +150,72 @@ class YHPlayer {
currentTitle
=
nil
}
func
play
(
url
:
String
,
title
:
String
?
=
nil
,
view
:
UIView
?)
{
// MARK: - Playback Control
func
play
(
url
:
String
,
title
:
String
?
=
nil
,
view
:
UIView
?,
isLive
:
Bool
=
false
)
{
currentURL
=
url
currentTitle
=
title
lastPlaybackInfo
=
(
url
,
title
)
// 保存播放信息
currentPlayView
=
view
playerKit
?
.
setRenderMode
(
.
fit
)
playerKit
?
.
setView
(
view
)
let
mediaSource
=
AgoraMediaSource
()
mediaSource
.
url
=
url
mediaSource
.
autoPlay
=
true
let
result
=
playerKit
?
.
open
(
with
:
mediaSource
)
if
result
==
0
{
playerKit
?
.
play
()
setPlayModeAndPlayView
(
isLive
?
.
live
:
.
vod
,
view
)
if
!
isLive
{
currentPlayView
=
view
playerKit
?
.
setRenderMode
(
.
fit
)
playerKit
?
.
setView
(
view
)
let
mediaSource
=
AgoraMediaSource
()
mediaSource
.
url
=
url
mediaSource
.
autoPlay
=
true
let
result
=
playerKit
?
.
open
(
with
:
mediaSource
)
if
result
==
0
{
playerKit
?
.
play
()
}
}
}
func
stop
()
{
playerKit
?
.
stop
()
clearJoinInfo
()
currentPlayView
=
nil
currentURL
=
nil
currentTitle
=
nil
// 保留 lastPlaybackInfo 用于恢复
if
playMode
==
.
vod
{
playerKit
?
.
stop
()
}
else
{
clearJoinInfo
()
}
}
func
pause
()
{
playerKit
?
.
pause
()
if
playMode
==
.
vod
{
playerKit
?
.
pause
()
}
}
func
resume
()
{
if
playerKit
?
.
getPlayerState
()
==
.
paused
{
playerKit
?
.
resume
()
}
else
{
playerKit
?
.
play
()
if
playMode
==
.
vod
{
if
playerKit
?
.
getPlayerState
()
==
.
paused
{
playerKit
?
.
resume
()
}
else
{
playerKit
?
.
play
()
}
}
}
func
resume
(
withNewView
view
:
UIView
)
{
// 设置新的播放视图
//setPlayView(view)
// 如果有频道信息,通知 Manager 重新加入频道
if
let
token
=
currentToken
,
let
channelId
=
currentChannelId
,
let
uid
=
currentUid
{
YHPlayerManager
.
shared
.
joinChannel
(
for
:
self
,
token
:
token
,
channelId
:
channelId
,
uid
:
uid
)
uid
:
uid
,
view
:
view
)
}
// 如果有上次的播放信息,重新播放
if
let
lastInfo
=
lastPlaybackInfo
,
let
url
=
lastInfo
.
url
{
play
(
url
:
url
,
title
:
lastInfo
.
title
,
view
:
view
)
if
let
url
=
currentURL
{
play
(
url
:
url
,
title
:
currentTitle
,
view
:
view
,
isLive
:
playMode
==
.
live
)
}
}
// MARK: - Resource Management
func
reset
()
{
stop
()
setPlay
View
(
nil
)
setPlay
ModeAndPlayView
(
playMode
,
nil
)
delegate
=
nil
lastPlaybackInfo
=
nil
}
func
releasePlayer
()
{
...
...
@@ -193,36 +223,35 @@ class YHPlayer {
playerKit
=
nil
}
// MARK: - Playback Info
// MARK: - Playback Info & Control
func
getPosition
()
->
Int
{
return
play
erKit
?
.
getPosition
()
??
0
return
play
Mode
==
.
vod
?
(
playerKit
?
.
getPosition
()
??
0
)
:
0
}
func
getDuration
()
->
Int
{
return
play
erKit
?
.
getDuration
()
??
0
return
play
Mode
==
.
vod
?
(
playerKit
?
.
getDuration
()
??
0
)
:
0
}
func
getPlayState
()
->
AgoraMediaPlayerState
{
return
play
erKit
?
.
getPlayerState
()
??
.
idle
return
play
Mode
==
.
vod
?
(
playerKit
?
.
getPlayerState
()
??
.
idle
)
:
.
playing
}
// MARK: - Seeking
func
seek
(
to
position
:
Int
)
{
playerKit
?
.
seek
(
toPosition
:
position
)
if
playMode
==
.
vod
{
playerKit
?
.
seek
(
toPosition
:
position
)
}
}
// MARK: - Volume Control
func
setVolume
(
_
volume
:
Int32
)
{
playerKit
?
.
adjustPlayoutVolume
(
volume
)
if
playMode
==
.
vod
{
playerKit
?
.
adjustPlayoutVolume
(
volume
)
}
}
// MARK: - Playback Speed
func
setPlaybackSpeed
(
_
speed
:
Double
)
{
playerKit
?
.
setPlaybackSpeed
(
Int32
(
speed
*
100
))
if
playMode
==
.
vod
{
playerKit
?
.
setPlaybackSpeed
(
Int32
(
speed
*
100
))
}
}
}
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/C/YHPlayerManager.swift
View file @
2fa1df59
...
...
@@ -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
)
}
}
}
}
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/C/YHVODPlayerViewController.swift
View file @
2fa1df59
...
...
@@ -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
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/M/YHLiveDetailModel.swift
View file @
2fa1df59
...
...
@@ -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
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/M/YHRecordedDetailModel.swift
View file @
2fa1df59
...
...
@@ -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
=
""
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/V/YHLiveMessageCell.swift
View file @
2fa1df59
...
...
@@ -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
}
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/V/YHLiveMessageListView.swift
View file @
2fa1df59
...
...
@@ -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
)
}
...
...
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/V/YHPlayerTopBarView.swift
View file @
2fa1df59
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment