PQSingletoVideoPlayer.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. //
  2. // PQVideoPlayer.swift
  3. // PQSpeed
  4. //
  5. // Created by SanW on 2020/6/3.
  6. // Copyright © 2020 BytesFlow. All rights reserved.
  7. //
  8. import UIKit
  9. import BFCommonKit
  10. public class PQSingletoVideoPlayer: NSObject {
  11. public static let shared = PQSingletoVideoPlayer()
  12. public var isPlayEnd: Bool = false // 是否已播放完成
  13. public var isHomePageAllList: Bool = false // 首页加入/关注是否是全部列表
  14. public var lastPlaybackTime: Float = 0 // 上次上报播放时长
  15. public var isRealPlay: Bool = false // 是否已真实播放
  16. public var isSemiRealPlay: Bool = false // 是否已播放到十秒
  17. public var isPlayBegin: Bool = false // 是否已缓冲完成开始播放
  18. public var isFirstFrame: Bool = false // 是否已显示第一帧加载完成
  19. public var isPlayerError: Bool = false // 是否播放失败
  20. public var loadingTime: TimeInterval = 0 // 加载时长
  21. public var playId: String = getUniqueId(desc: "playId") // 播放ID
  22. /// 进度回调
  23. public var progressBloc: ((_ loadProgress: Float, _ playProgress: Float, _ duration: Float) -> Void)?
  24. /// 播放状态回调
  25. public var playStatusBloc: ((_ playStatus: PQVIDEO_PLAY_STATUS) -> Void)?
  26. public var playControllerView: UIView?
  27. public var playVideoData: BFVideoItemProtocol?
  28. public var isPlaying: Bool {
  29. return player.isPlaying()
  30. }
  31. public var autoResumePlayWhenEnterForeground:Bool = true
  32. var shouldResumePlayWhenEnterForeground:Bool = false
  33. public lazy var player: TXVodPlayer = {
  34. let player = TXVodPlayer()
  35. let config = TXVodPlayConfig()
  36. config.cacheFolderPath = videoCacheDirectory
  37. config.maxCacheItems = 5
  38. player.config = config
  39. player.vodDelegate = self
  40. player.setRenderMode(.RENDER_MODE_FILL_SCREEN)
  41. return player
  42. }()
  43. /// 配置播放器
  44. /// - Parameters:
  45. /// - videoData: <#videoData description#>
  46. /// - controllerView: <#controllerView description#>
  47. public func configPlyer(videoData: BFVideoItemProtocol, controllerView: UIView, renderMode: TX_Enum_Type_RenderMode = .RENDER_MODE_FILL_SCREEN,isAllList:Bool = false) {
  48. // if playVideoData?.id == videoData.id {
  49. // return
  50. // }
  51. isHomePageAllList = isAllList
  52. isPlayEnd = false
  53. isRealPlay = false
  54. isSemiRealPlay = false
  55. isPlayBegin = false
  56. isFirstFrame = false
  57. isPlayerError = false
  58. loadingTime = Date().timeIntervalSince1970 * 1000
  59. player.setRenderMode(renderMode)
  60. player.stopPlay()
  61. player.removeVideoWidget()
  62. player.setupVideoWidget(controllerView, insert: 0)
  63. player.enableHWAcceleration = true
  64. playControllerView = controllerView
  65. playVideoData = videoData
  66. if playVideoData!.playProgress >= 0.0 {
  67. var progress: CGFloat = CGFloat(playVideoData!.playProgress)
  68. if progress > 5.0, progress < 20 {
  69. progress = progress - 5.0
  70. if progress <= 0 {
  71. progress = 0
  72. }
  73. }
  74. BFLog(message: "xxx.playProgress =\(playVideoData!.playProgress),\(progress)")
  75. player.setStartTime(progress)
  76. }
  77. playId = getUniqueId(desc: "playId")
  78. lastPlaybackTime = 0
  79. BFLog(message: "\(String(describing: videoData.title)) 开始播放 \(videoData.videoPath ?? "")")
  80. if PQSingletoMemoryUtil.shared.playCount < 4 {
  81. PQSingletoMemoryUtil.shared.playCount = PQSingletoMemoryUtil.shared.playCount + 1
  82. }
  83. }
  84. public func reRenderView(newView: UIView) {
  85. player.removeVideoWidget()
  86. player.setupVideoWidget(newView, insert: 0)
  87. }
  88. /// 重制播放
  89. public func resetPlayer() {
  90. if playControllerView != nil {
  91. let playDuration = player.currentPlaybackTime() - lastPlaybackTime
  92. debugPrint("当前播放时长:\(player.currentPlaybackTime()),lastPlaybackTime:\(lastPlaybackTime),playDuration:\(playDuration)")
  93. if playDuration > 0 {
  94. var extParams:[String:Any]?
  95. if isHomePageAllList {
  96. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  97. extParams = ["topicId":"all"]
  98. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  99. extParams = ["followedUid":"all"]
  100. }
  101. }
  102. PQEventTrackViewModel.baseReportUpload(logType: .st_log_type_pLayaction,businessType: .bt_videoPlayDuration, objectType: nil, pageSource: playVideoData?.pageSource ?? .sp_cmunit_recommend, eventData: ["pageSource":(playVideoData?.pageSource ?? .sp_cmunit_recommend).rawValue,"playDuration":Int64(playDuration * 1000),"playId":playId,"uid":"\(playVideoData?.user?["uid"] ?? "")","videoId":playVideoData?.id ?? 0], extParams: extParams, remindmsg: "播放时长统计")
  103. lastPlaybackTime = player.currentPlaybackTime()
  104. }
  105. player.removeVideoWidget()
  106. player.setupVideoWidget(playControllerView, insert: 0)
  107. if playVideoData!.playProgress >= 0.0 {
  108. //
  109. var progress: CGFloat = CGFloat(playVideoData!.playProgress)
  110. if progress > 5.0, progress < 20 {
  111. progress = progress - 5.0
  112. if progress <= 0 {
  113. progress = 0
  114. }
  115. }
  116. BFLog(message: "xxx.playProgress =\(playVideoData!.playProgress),\(progress)")
  117. player.setStartTime(progress)
  118. }
  119. playId = getUniqueId(desc: "playId")
  120. // 开始播放
  121. startPlayr()
  122. }
  123. }
  124. /// 开始播放
  125. public func startPlayr() {
  126. BFLog(message: "开始播放 \(playVideoData?.videoPath ?? "")")
  127. if isValidURL(url: playVideoData?.videoPath) {
  128. player.startPlay(playVideoData?.videoPath)
  129. }
  130. }
  131. /// 暂停播放
  132. public func pausePlayer() {
  133. player.pause()
  134. let playDuration = player.currentPlaybackTime() - lastPlaybackTime
  135. debugPrint("当前播放时长:\(player.currentPlaybackTime()),lastPlaybackTime:\(lastPlaybackTime),playDuration:\(playDuration)")
  136. if playDuration > 0 {
  137. var extParams:[String:Any]?
  138. if isHomePageAllList {
  139. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  140. extParams = ["topicId":"all"]
  141. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  142. extParams = ["followedUid":"all"]
  143. }
  144. }
  145. PQEventTrackViewModel.baseReportUpload(logType: .st_log_type_pLayaction,businessType: .bt_videoPlayDuration, objectType: nil, pageSource: playVideoData?.pageSource ?? .sp_cmunit_recommend, eventData: ["pageSource":(playVideoData?.pageSource ?? .sp_cmunit_recommend).rawValue,"playDuration":Int64(playDuration * 1000),"playId":playId,"uid":"\(playVideoData?.user?["uid"] ?? "")","videoId":playVideoData?.id ?? 0], extParams: extParams, remindmsg: "播放时长统计")
  146. lastPlaybackTime = player.currentPlaybackTime()
  147. }
  148. }
  149. /// 继续播放
  150. public func resumePlayer(renderMode: TX_Enum_Type_RenderMode? = nil) {
  151. player.resume()
  152. if renderMode != nil {
  153. player.setRenderMode(renderMode!)
  154. }
  155. let playDuration = player.currentPlaybackTime() - lastPlaybackTime
  156. debugPrint("当前播放时长:\(player.currentPlaybackTime()),lastPlaybackTime:\(lastPlaybackTime),playDuration:\(playDuration)")
  157. if playDuration > 0 {
  158. var extParams:[String:Any]?
  159. if isHomePageAllList {
  160. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  161. extParams = ["topicId":"all"]
  162. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  163. extParams = ["followedUid":"all"]
  164. }
  165. }
  166. PQEventTrackViewModel.baseReportUpload(logType: .st_log_type_pLayaction,businessType: .bt_videoPlayDuration, objectType: nil, pageSource: playVideoData?.pageSource ?? .sp_cmunit_recommend, eventData: ["pageSource":(playVideoData?.pageSource ?? .sp_cmunit_recommend).rawValue,"playDuration":Int64(playDuration * 1000),"playId":playId,"uid":"\(playVideoData?.user?["uid"] ?? "")","videoId":playVideoData?.id ?? 0], extParams: extParams, remindmsg: "播放时长统计")
  167. lastPlaybackTime = player.currentPlaybackTime()
  168. }
  169. }
  170. /// 停止播放
  171. /// - Parameter isRemove: 是否移除载体视图
  172. public func stopPlayer(isRemove: Bool = true) {
  173. player.stopPlay()
  174. if isRemove {
  175. player.removeVideoWidget()
  176. playControllerView = nil
  177. playVideoData = nil
  178. }
  179. let playDuration = player.currentPlaybackTime() - lastPlaybackTime
  180. debugPrint("当前播放时长:\(player.currentPlaybackTime()),lastPlaybackTime:\(lastPlaybackTime),playDuration:\(playDuration)")
  181. if playDuration > 0 {
  182. var extParams:[String:Any]?
  183. if isHomePageAllList {
  184. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  185. extParams = ["topicId":"all"]
  186. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  187. extParams = ["followedUid":"all"]
  188. }
  189. }
  190. PQEventTrackViewModel.baseReportUpload(logType: .st_log_type_pLayaction,businessType: .bt_videoPlayDuration, objectType: nil, pageSource: playVideoData?.pageSource ?? .sp_cmunit_recommend, eventData: ["pageSource":(playVideoData?.pageSource ?? .sp_cmunit_recommend).rawValue,"playDuration":Int64(playDuration * 1000),"playId":playId,"uid":"\(playVideoData?.user?["uid"] ?? "")","videoId":playVideoData?.id ?? 0], extParams: extParams, remindmsg: "播放时长统计")
  191. lastPlaybackTime = player.currentPlaybackTime()
  192. }
  193. }
  194. /// seek
  195. /// - Parameter time: <#time description#>
  196. public func seek(time: Float) {
  197. player.seek(time)
  198. }
  199. override private init() {
  200. super.init()
  201. NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { notice in
  202. if self.isPlaying {
  203. self.pausePlayer()
  204. self.shouldResumePlayWhenEnterForeground = true
  205. }
  206. }
  207. NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: nil) { notice in
  208. if self.autoResumePlayWhenEnterForeground && self.shouldResumePlayWhenEnterForeground {
  209. self.shouldResumePlayWhenEnterForeground = false
  210. self.resumePlayer()
  211. }
  212. }
  213. }
  214. override public func copy() -> Any {
  215. return self
  216. }
  217. override public func mutableCopy() -> Any {
  218. return self
  219. }
  220. }
  221. extension PQSingletoVideoPlayer: TXVodPlayListener {
  222. /// 播放进度回调
  223. /// - Parameters:
  224. /// - player: <#player description#>
  225. /// - EvtID: <#EvtID description#>
  226. /// - param: <#param description#>
  227. public func onPlayEvent(_ player: TXVodPlayer!, event: Int32, withParam param: [AnyHashable: Any]!) {
  228. if event != PLAY_EVT_PLAY_PROGRESS.rawValue {
  229. BFLog(message: "播放器状态回调:event:\(event),status:\(EventID(event)),param:\(param ?? [:])")
  230. }
  231. switch event {
  232. case PLAY_EVT_PLAY_PROGRESS.rawValue: // 播放进度
  233. // 加载进度, 单位是秒
  234. let loadProgress: Float = param[EVT_PLAYABLE_DURATION] as! Float
  235. // 播放进度, 单位是秒
  236. let playProgress: Float = param[EVT_PLAY_PROGRESS] as! Float
  237. // 总长度, 单位是秒
  238. let duration: Float = param[EVT_PLAY_DURATION] as! Float
  239. if player.currentPlaybackTime() >= 10.0, player.currentPlaybackTime() <= 10.1 {
  240. // 10.0上报
  241. if !isSemiRealPlay, playVideoData != nil {
  242. isSemiRealPlay = true
  243. // 播放上报
  244. var extParams:[String:Any]?
  245. if isHomePageAllList {
  246. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  247. extParams = ["topicId":"all"]
  248. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  249. extParams = ["followedUid":"all"]
  250. }
  251. }
  252. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: playVideoData, pageSource: nil, businessType: .bt_videoSemiRealPlay, objectType: nil, extParams:extParams , shareId: nil, videoIds: nil, playId: playId)
  253. }
  254. }
  255. if player.currentPlaybackTime() >= 20.0 || ((playProgress / duration) >= 0.3) {
  256. // 视频播放到20s或播放到总时长30%,哪个先到为准
  257. if !isRealPlay, playVideoData != nil {
  258. isRealPlay = true
  259. // 播放上报
  260. var extParams:[String:Any]?
  261. if isHomePageAllList {
  262. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  263. extParams = ["topicId":"all"]
  264. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  265. extParams = ["followedUid":"all"]
  266. }
  267. }
  268. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_realPlay, videoData: playVideoData, pageSource: nil, businessType: .bt_videoRealPlay, objectType: nil, extParams: extParams, shareId: nil, videoIds: nil, playId: playId)
  269. }
  270. }
  271. playVideoData?.playProgress = Float64(playProgress)
  272. if progressBloc != nil {
  273. progressBloc!(loadProgress, playProgress, duration)
  274. }
  275. case PLAY_EVT_RCV_FIRST_I_FRAME.rawValue:
  276. // 首帧完成开始播放
  277. if !isPlayBegin, playVideoData != nil {
  278. isPlayBegin = true
  279. // 播放上报
  280. var extParams:[String:Any]?
  281. if isHomePageAllList {
  282. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  283. extParams = ["topicId":"all"]
  284. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  285. extParams = ["followedUid":"all"]
  286. }
  287. }
  288. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlaySuccess, objectType: nil, extParams: extParams, shareId: nil, videoIds: nil, playId: playId)
  289. }
  290. case PLAY_EVT_PLAY_LOADING.rawValue: // 视频播放loading
  291. if playStatusBloc != nil {
  292. playStatusBloc!(.PQVIDEO_PLAY_STATUS_LOADING)
  293. }
  294. case PLAY_EVT_PLAY_BEGIN.rawValue: // 开始播放
  295. if playStatusBloc != nil {
  296. playStatusBloc!(.PQVIDEO_PLAY_STATUS_BEGIN)
  297. }
  298. // 首帧加载完成
  299. if !isFirstFrame, playVideoData != nil {
  300. isFirstFrame = true
  301. // 播放上报
  302. var extParams:[String:Any]?
  303. if isHomePageAllList {
  304. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  305. extParams = ["topicId":"all"]
  306. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  307. extParams = ["followedUid":"all"]
  308. }
  309. }
  310. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_play, videoData: playVideoData, pageSource: nil, businessType: nil, objectType: nil, extParams: extParams, shareId: nil, videoIds: nil, playId: playId)
  311. let duration = Int((Date().timeIntervalSince1970 * 1000) - loadingTime)
  312. BFLog(message: "加载时长:\(duration)")
  313. // 加载时间上报
  314. var timeExtParams:[String:Any] = ["duration": duration, "proxyEnable": "0", "url": playVideoData?.videoPath ?? "", "videoId": playVideoData?.uniqueId ?? "0"]
  315. if extParams != nil {
  316. timeExtParams.merge(extParams!) { keyValue, param in
  317. return keyValue
  318. }
  319. }
  320. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Frontend, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlaySuccessTime, objectType: nil, extParams: timeExtParams, shareId: nil, videoIds: nil, playId: playId)
  321. }
  322. BFLog(message: "首帧加载完成")
  323. case PLAY_EVT_PLAY_END.rawValue: // 播放结束
  324. player.pause()
  325. playId = getUniqueId(desc: "playId")
  326. if playStatusBloc != nil {
  327. playStatusBloc!(.PQVIDEO_PLAY_STATUS_END)
  328. }
  329. if !isPlayEnd, playVideoData != nil {
  330. isPlayEnd = true
  331. // 播放结束上报
  332. var extParams:[String:Any]?
  333. if isHomePageAllList {
  334. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  335. extParams = ["topicId":"all"]
  336. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  337. extParams = ["followedUid":"all"]
  338. }
  339. }
  340. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlayEnd, objectType: nil, extParams: extParams, shareId: nil, videoIds: nil, playId: playId)
  341. }
  342. let playDuration = player.currentPlaybackTime() - lastPlaybackTime
  343. debugPrint("当前播放时长:\(player.currentPlaybackTime()),lastPlaybackTime:\(lastPlaybackTime),playDuration:\(playDuration)")
  344. if playDuration > 0 {
  345. var extParams:[String:Any]?
  346. if isHomePageAllList {
  347. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  348. extParams = ["topicId":"all"]
  349. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  350. extParams = ["followedUid":"all"]
  351. }
  352. }
  353. PQEventTrackViewModel.baseReportUpload(logType: .st_log_type_pLayaction,businessType: .bt_videoPlayDuration, objectType: nil, pageSource: playVideoData?.pageSource ?? .sp_cmunit_recommend, eventData: ["pageSource":(playVideoData?.pageSource ?? .sp_cmunit_recommend).rawValue,"playDuration":Int64(playDuration * 1000),"playId":playId,"uid":"\(playVideoData?.user?["uid"] ?? "")","videoId":playVideoData?.id ?? 0], extParams: extParams, remindmsg: "播放时长统计")
  354. lastPlaybackTime = player.currentPlaybackTime()
  355. }
  356. case PLAY_ERR_NET_DISCONNECT.rawValue, -2301: // 重连失败
  357. if playStatusBloc != nil {
  358. playStatusBloc!(.PQVIDEO_PLAY_STATUS_DISCONNECT)
  359. }
  360. if !isPlayerError, playVideoData != nil {
  361. isPlayerError = true
  362. // 播放失败
  363. var extParams:[String:Any] = ["pageSource": playVideoData!.pageSource.rawValue, "networkType": networkStatus(), "extra": "0", "hasRetry": true, "url": playVideoData?.videoPath ?? "", "videoId": playVideoData?.uniqueId ?? "0", "what": event]
  364. if isHomePageAllList {
  365. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  366. extParams["topicId"] = "all"
  367. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  368. extParams["followedUid"] = "all"
  369. }
  370. }
  371. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlayError, objectType: nil, extParams: extParams, shareId: nil, videoIds: nil, playId: playId)
  372. }
  373. case PLAY_ERR_FILE_NOT_FOUND.rawValue: // 播放文件不存在
  374. if playStatusBloc != nil {
  375. playStatusBloc!(.PQVIDEO_PLAY_STATUS_NOT_FOUND)
  376. }
  377. if !isPlayerError, playVideoData != nil {
  378. isPlayerError = true
  379. // 播放失败
  380. var extParams:[String:Any] = ["pageSource": playVideoData!.pageSource.rawValue, "networkType": networkStatus(), "extra": "0", "hasRetry": false, "url": playVideoData?.videoPath ?? "", "videoId": playVideoData?.uniqueId ?? "0", "what": event]
  381. if isHomePageAllList {
  382. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  383. extParams["topicId"] = "all"
  384. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  385. extParams["followedUid"] = "all"
  386. }
  387. }
  388. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlayError, objectType: nil, extParams:extParams , shareId: nil, videoIds: nil, playId: playId)
  389. }
  390. case PLAY_ERR_HEVC_DECODE_FAIL.rawValue, PLAY_ERR_HLS_KEY.rawValue, PLAY_ERR_GET_PLAYINFO_FAIL.rawValue, PLAY_WARNING_VIDEO_DECODE_FAIL.rawValue, PLAY_WARNING_AUDIO_DECODE_FAIL.rawValue: // H265解码失败,HLS解码key获取失败,获取点播文件信息失败,当前视频解码失败,当前音频解码失败
  391. if playStatusBloc != nil {
  392. playStatusBloc!(.PQVIDEO_PLAY_STATUS_FAUILE)
  393. }
  394. if !isPlayerError, playVideoData != nil {
  395. isPlayerError = true
  396. // 播放失败
  397. var extParams:[String:Any] = ["pageSource": playVideoData!.pageSource.rawValue, "networkType": networkStatus(), "extra": "0", "hasRetry": false, "url": playVideoData?.videoPath ?? "", "videoId": playVideoData?.uniqueId ?? "0", "what": event]
  398. if isHomePageAllList {
  399. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  400. extParams["topicId"] = "all"
  401. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  402. extParams["followedUid"] = "all"
  403. }
  404. }
  405. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlayError, objectType: nil, extParams: extParams, shareId: nil, videoIds: nil, playId: playId)
  406. }
  407. case PLAY_WARNING_RECONNECT.rawValue: // 断线重连已启动重新连接
  408. if playStatusBloc != nil {
  409. playStatusBloc!(.PQVIDEO_PLAY_STATUS_RECONNECT)
  410. }
  411. var extParams:[String:Any] = ["pageSource": playVideoData!.pageSource.rawValue, "networkType": networkStatus(), "extra": "0", "hasRetry": true, "url": playVideoData?.videoPath ?? "", "videoId": playVideoData?.uniqueId ?? "0", "what": event]
  412. if isHomePageAllList {
  413. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  414. extParams["topicId"] = "all"
  415. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  416. extParams["followedUid"] = "all"
  417. }
  418. }
  419. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlayException, objectType: nil, extParams: extParams, shareId: nil, videoIds: nil, playId: playId)
  420. case PLAY_WARNING_RECV_DATA_LAG.rawValue, PLAY_WARNING_VIDEO_PLAY_LAG.rawValue: // 网络来包不稳:可能是下行带宽不足 | 当前视频播放出现卡顿(用户直观感受)
  421. // 播放失败
  422. var extParams1:[String:Any] = ["pageSource": playVideoData!.pageSource.rawValue, "networkType": networkStatus(), "url": playVideoData?.videoPath ?? "", "videoId": playVideoData?.uniqueId ?? "0", "what": event, "position": player.currentPlaybackTime()]
  423. var extParams2:[String:Any] = ["pageSource": playVideoData!.pageSource.rawValue, "networkType": networkStatus(), "extra": "0", "hasRetry": true, "url": playVideoData?.videoPath ?? "", "videoId": playVideoData?.uniqueId ?? "0", "what": event]
  424. if isHomePageAllList {
  425. if playVideoData?.pageSource == .sp_cmunit_joinTopic {
  426. extParams1["topicId"] = "all"
  427. extParams2["topicId"] = "all"
  428. } else if playVideoData?.pageSource == .sp_cmunit_follow {
  429. extParams1["followedUid"] = "all"
  430. extParams2["topicId"] = "all"
  431. }
  432. }
  433. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Frontend, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlaySlow, objectType: nil, extParams: extParams1, shareId: nil, videoIds: nil, playId: playId)
  434. PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: playVideoData, pageSource: nil, businessType: .bt_videoPlayException, objectType: nil, extParams: extParams2, shareId: nil, videoIds: nil, playId: playId)
  435. default:
  436. break
  437. }
  438. }
  439. /// 网络状态回调
  440. /// - Parameters:
  441. /// - player: <#player description#>
  442. /// - param: <#param description#>
  443. public func onNetStatus(_: TXVodPlayer!, withParam _: [AnyHashable: Any]!) {
  444. // BFLog(message: "onNetStatus:\(param)")
  445. }
  446. }