Przeglądaj źródła

1.修改播放器

wenweiwei 3 lat temu
rodzic
commit
8f4bb27ace

+ 20 - 6
BFFramework/Classes/BFModules/BFUtility/PQSingletoVideoPlayer.swift

@@ -13,7 +13,7 @@ public class PQSingletoVideoPlayer: NSObject {
     public static let shared = PQSingletoVideoPlayer()
     public var isPlayEnd: Bool = false // 是否已播放完成
     public var isRealPlay: Bool = false // 是否已真实播放
-    public  var isSemiRealPlay: Bool = false // 是否已播放到十秒
+    public var isSemiRealPlay: Bool = false // 是否已播放到十秒
     public var isPlayBegin: Bool = false // 是否已缓冲完成开始播放
     public var isFirstFrame: Bool = false // 是否已显示第一帧加载完成
     public var isPlayerError: Bool = false // 是否播放失败
@@ -40,6 +40,10 @@ public class PQSingletoVideoPlayer: NSObject {
         return player
     }()
 
+    /// 配置播放器
+    /// - Parameters:
+    ///   - videoData: <#videoData description#>
+    ///   - controllerView: <#controllerView description#>
     public func configPlyer(videoData: PQVideoListModel, controllerView: UIView) {
         isPlayEnd = false
         isRealPlay = false
@@ -48,10 +52,8 @@ public class PQSingletoVideoPlayer: NSObject {
         isFirstFrame = false
         isPlayerError = false
         loadingTime = Date().timeIntervalSince1970 * 1000
-
         player.stopPlay()
         player.removeVideoWidget()
-
         player.setupVideoWidget(controllerView, insert: 0)
         player.enableHWAcceleration = true
         playControllerView = controllerView
@@ -70,13 +72,12 @@ public class PQSingletoVideoPlayer: NSObject {
         }
         playId = getUniqueId(desc: "playId")
         BFLog(message: "\(String(describing: videoData.title)) 开始播放 \(videoData.videoPath ?? "")")
-        player.startPlay(videoData.videoPath)
-
         if PQSingletoMemoryUtil.shared.playCount < 4 {
             PQSingletoMemoryUtil.shared.playCount = PQSingletoMemoryUtil.shared.playCount + 1
         }
     }
 
+    /// 重制播放
     public func resetPlayer() {
         if playControllerView != nil {
             player.removeVideoWidget()
@@ -94,18 +95,31 @@ public class PQSingletoVideoPlayer: NSObject {
                 player.setStartTime(progress)
             }
             playId = getUniqueId(desc: "playId")
-            player.startPlay(playVideoData!.videoPath)
+            // 开始播放
+            startPlayr()
+        }
+    }
+
+    /// 开始播放
+    public func startPlayr() {
+        BFLog(message: "开始播放 \(playVideoData?.videoPath ?? "")")
+        if isValidURL(url: playVideoData?.videoPath) {
+            player.startPlay(playVideoData?.videoPath)
         }
     }
 
+    /// 暂停播放
     public func pausePlayer() {
         player.pause()
     }
 
+    /// 继续播放
     public func resumePlayer() {
         player.resume()
     }
 
+    /// 停止播放
+    /// - Parameter isRemove: 是否移除载体视图
     public func stopPlayer(isRemove: Bool = true) {
         player.stopPlay()
         if isRemove {