소스 검색

添加是否使用 avplayer 播放音频

jsonwang 3 년 전
부모
커밋
ebf7b1d476

+ 9 - 6
BFFramework/Classes/PQGPUImage/akfilters/PQMovieInput.swift

@@ -130,7 +130,10 @@ public class PQMovieInput: ImageSource {
 //    public  var seekQueue: DispatchQueue!
 
     // 是否为导出模式
-    public   var mIsExport: Bool = false
+    public var mIsExport: Bool = false
+    
+    //是否使用AVPlayer播放音乐
+    public var isUsedAVPlayer:Bool = false
     
     //打印开始时间
     var debugStartTime:CFTimeInterval?
@@ -170,10 +173,10 @@ public class PQMovieInput: ImageSource {
 
         if #available(iOS 10, *){
             displayLink?.preferredFramesPerSecond = 30
-//            seekQueue = DispatchQueue(label: "PQ.MovieInput.seeking", qos: .userInteractive, attributes: .initiallyInactive, autoreleaseFrequency: .never, target: nil)
+ 
         }else{
             displayLink?.frameInterval = 2
-//            seekQueue = DispatchQueue(label: "PQ.MovieInput.seeking", qos: .userInteractive, attributes: [], autoreleaseFrequency: .inherit, target: nil)
+ 
         }
         // 加入循环 要使用 common 不要让级别高的卡住回调事件
         displayLink?.add(to: RunLoop.main, forMode: RunLoop.Mode.common)
@@ -337,7 +340,7 @@ public class PQMovieInput: ImageSource {
         mIsExport = isExport
         do {
             try NSObject.catchException { [self] in
-                if(mIsExport){
+                if(!isUsedAVPlayer){
                     guard self.assetReader.startReading() else {
                         BFLog(2, message: "ERROR: Unable to start reading: \(String(describing: self.assetReader.error))")
                         return
@@ -509,8 +512,8 @@ public class PQMovieInput: ImageSource {
 
     func readNextAudioSample(with assetReader: AVAssetReader, from audioTrackOutput: AVAssetReaderOutput) {
         
-        if(!mIsExport){
-            BFLog(2, message: "不是导出模式")
+        if(isUsedAVPlayer){
+            BFLog(2, message: "使用的 avplayer 播放模式")
             return
         }
        

+ 1 - 1
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -1150,7 +1150,7 @@ class PQStuckPointEditerController: PQBaseViewController {
                 // 这里的测试这个音乐播放有问题
                 //        self.playerView.updateAsset(URL(fileURLWithPath: "63930549652d74e477141e3b79c8d29a9ef8af81625053214516.mp3", relativeTo:Bundle.main.resourceURL!), videoComposition: nil, audioMixModel: nil)
 
-                self.playerView.updateAsset(URL(fileURLWithPath: documensDirectory + audioPath), videoComposition: nil, audioMixModel: nil, originMusicDuration: self.finallyUserAudioTime, clipAudioRange: self.getClipAudioRange())
+                self.playerView.updateAsset(URL(fileURLWithPath: documensDirectory + audioPath), videoComposition: nil, audioMixModel: nil, originMusicDuration: self.finallyUserAudioTime, clipAudioRange: self.getClipAudioRange(),isUsedAVPlayer: true)
 
                 // 4, 设置播放器的输出画布大小
                 self.playerView.movie?.mShowVidoSize = CGSize(width: CGFloat(self.projectModel.sData?.videoMetaData?.videoWidth ?? 0), height: CGFloat(self.projectModel.sData?.videoMetaData?.videoHeight ?? 0))

+ 7 - 1
BFFramework/Classes/Stuckpoint/ViewModel/PQGPUImagePlayerView.swift

@@ -149,6 +149,9 @@ public class PQGPUImagePlayerView: UIView {
     
     //是否显示高斯
     public  var showGaussianBlur:Bool = false
+    
+    //是否使用AVPlayer播放音乐
+    public var isUsedAVPlayer:Bool = false
 
     // 渲染区view
     private lazy var renderView: RenderView = {
@@ -361,7 +364,8 @@ public class PQGPUImagePlayerView: UIView {
     }
 
     /// XXXX 这里的 URL 使用的是全路径 ,如果不是全的会 crash ,方便复用 (不用处理业务的文件放在哪里)
-    public func updateAsset(_ url: URL, videoComposition: AVVideoComposition? = nil, audioMixModel: PQVoiceModel? = nil, videoStickers: [PQEditVisionTrackMaterialsModel]? = nil,originMusicDuration:Float = 0,lastPoint:Float = 0,clipAudioRange: CMTimeRange = CMTimeRange.zero ) {
+    public func updateAsset(_ url: URL, videoComposition: AVVideoComposition? = nil, audioMixModel: PQVoiceModel? = nil, videoStickers: [PQEditVisionTrackMaterialsModel]? = nil,originMusicDuration:Float = 0,lastPoint:Float = 0,clipAudioRange: CMTimeRange = CMTimeRange.zero ,isUsedAVPlayer:Bool = false) {
+        self.isUsedAVPlayer = isUsedAVPlayer
         // 每次初始化的时候设置初始值 为 nIl
         var audioMix: AVMutableAudioMix?
         var composition: AVMutableComposition?
@@ -417,6 +421,8 @@ public class PQGPUImagePlayerView: UIView {
 
             movie!.runBenchmark = false
             movie!.synchronizedEncodingDebug = false
+            
+            movie!.isUsedAVPlayer = isUsedAVPlayer
 
         } catch {
             status = .error