Jelajahi Sumber

Merge branch 'master' of https://git.yishihui.com/iOS/BFFramework
合并代码

jsonwang 3 tahun lalu
induk
melakukan
53d7ec79b1

+ 1 - 0
BFFramework/Classes/BFFramework_custom_umbrella.h

@@ -19,5 +19,6 @@
 #import "UIControl+NXCategory.h"
 #import <TXLiteAVSDK_Player/TXLiteAVSDK.h>
 #import <Bugly/Bugly.h>
+#import "MemoryCoculation.h"
 
 #endif /* AliyunOSSiOS_Bridging_Header */

+ 16 - 0
BFFramework/Classes/BFModules/BFUtility/MemoryCoculation.h

@@ -0,0 +1,16 @@
+//
+//  MemoryCoculation.h
+//  BFFramework
+//
+//  Created by Harry Hu on 2021/10/13.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MemoryCoculation : NSObject
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 22 - 0
BFFramework/Classes/BFModules/BFUtility/MemoryCoculation.m

@@ -0,0 +1,22 @@
+//
+//  MemoryCoculation.m
+//  BFFramework
+//
+//  Created by Harry Hu on 2021/10/13.
+//
+
+#import "MemoryCoculation.h"
+
+@implementation MemoryCoculation
+
++ (int64_t)memoryResidentSize {
+    struct task_basic_info info;
+//    mach_msg_type_number_t size = sizeof(task_basic_info_data_t) / sizeof(natural_t);
+//    kern_return_t ret = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
+//    if (ret != KERN_SUCCESS) {
+//        return 0;
+//    }
+    return info.resident_size;
+}
+
+@end

+ 14 - 0
BFFramework/Classes/Stuckpoint/Controller/PQEditMusicSearchController.swift

@@ -167,6 +167,7 @@ class PQEditMusicSearchController: PQBaseViewController {
         }
     }
     
+    var avPlayerTimeObserver:Any?
     /// 播放音乐
     /// - Parameter itemData: <#itemData description#>
     func playStuckPointMusic(itemData: PQVoiceModel?, isClearCurrentMusic: Bool = false) {
@@ -178,6 +179,10 @@ class PQEditMusicSearchController: PQBaseViewController {
             avPlayer.pause()
             playerItem?.removeObserver(self, forKeyPath: "status")
             playerItem?.removeObserver(self, forKeyPath: "error")
+            if avPlayerTimeObserver != nil {
+                avPlayer.removeTimeObserver(avPlayerTimeObserver as Any)
+            }
+            
             playerItem = AVPlayerItem(url: URL(string: itemData?.musicPath ?? "")!)
             if (itemData?.endTime ?? 0) > 0, (itemData?.endTime ?? 0) > (itemData?.startTime ?? 0) {
                 playerItem?.forwardPlaybackEndTime = CMTime(value: CMTimeValue((itemData?.endTime ?? 0) * playerTimescale), timescale: CMTimeScale(playerTimescale))
@@ -187,6 +192,15 @@ class PQEditMusicSearchController: PQBaseViewController {
             playerItem?.addObserver(self, forKeyPath: "error", options: .new, context: nil)
             avPlayer.seek(to: CMTime(value: CMTimeValue((itemData?.startTime ?? 0) * playerTimescale), timescale: CMTimeScale(playerTimescale)))
             avPlayer.play()
+            
+            avPlayerTimeObserver = avPlayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 10), queue: DispatchQueue.global()) {[weak self] time in
+                if fabs(CMTimeGetSeconds(time) - (itemData?.startTime ?? 0)) > 0.1 {
+                    self?.avPlayer.removeTimeObserver(self?.avPlayerTimeObserver as Any)
+                    self?.avPlayerTimeObserver = nil
+                    // 停止cell loading动画
+                    PQNotification.post(name: NSNotification.Name(rawValue: "MusicContentCellIconLoadingAnimationStop"), object: nil)
+                }
+            }
 //            let player = TXVodPlayer()
 //            let config = TXVodPlayConfig()
 //            config.cacheFolderPath = videoCacheDirectory

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

@@ -1142,7 +1142,7 @@ extension PQStuckPointEditerController {
                 let clipNum = Int(max(round(Double(kongduan) * CMTimeGetSeconds(asset.duration) / videoTotalDuration), 1))
                 sticker.duration = CMTimeGetSeconds(asset.duration)
                 BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(clipNum)")
-                for clipindex in 0 ... clipNum - 1 {
+                for clipindex in 0 ..< clipNum {
                     // deep copy sticker model 防止只有一个对象
                     let deepCopySticker:PQEditVisionTrackMaterialsModel? = sticker.copy() as? PQEditVisionTrackMaterialsModel
                               
@@ -1169,7 +1169,7 @@ extension PQStuckPointEditerController {
                 stickers.append(sticker)
             }
         }
-
+//        kongduan = clipNumTep
         return stickers
     }
     

+ 3 - 0
BFFramework/Classes/Stuckpoint/View/PQStuckPointMusicContentCell.swift

@@ -106,6 +106,9 @@ class PQStuckPointMusicContentCell: UICollectionViewCell {
     required init?(coder _: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
+    deinit {
+        PQNotification.removeObserver(self)
+    }
 
     var bgmData: Any? {
         didSet {