Parcourir la source

feat:加入example,修复bug

kailen il y a 2 mois
Parent
commit
1dfc2f80a7
21 fichiers modifiés avec 151 ajouts et 18 suppressions
  1. 2 2
      Podfile.lock
  2. 16 0
      TSLiveWallpaper.xcodeproj/project.pbxproj
  3. 5 0
      TSLiveWallpaper/AppDelegate.swift
  4. BIN
      TSLiveWallpaper/Assets.xcassets/.DS_Store
  5. BIN
      TSLiveWallpaper/Assets.xcassets/Music/ic_addplaylist.imageset/ic_addplaylist@1x.png
  6. BIN
      TSLiveWallpaper/Assets.xcassets/Music/ic_addplaylist.imageset/ic_addplaylist@2x.png
  7. BIN
      TSLiveWallpaper/Assets.xcassets/Music/ic_addplaylist.imageset/ic_addplaylist@3x.png
  8. 3 0
      TSLiveWallpaper/Assets.xcassets/Music/ic_default.imageset/Contents.json
  9. 12 1
      TSLiveWallpaper/Business/TSMusic/Custom/PlayMiniBar.swift
  10. 1 0
      TSLiveWallpaper/Business/TSMusic/Detail/PlayerManager.swift
  11. 1 1
      TSLiveWallpaper/Business/TSMusic/Helper/FilterBarView.swift
  12. 4 2
      TSLiveWallpaper/Business/TSMusic/List/Controller/MusicContainerViewController.swift
  13. 2 2
      TSLiveWallpaper/Business/TSMusic/List/View/SongListCell.swift
  14. 1 1
      TSLiveWallpaper/Business/TSMusic/PlayList/Controller/AddPlayListViewController.swift
  15. 3 2
      TSLiveWallpaper/Business/TSMusic/PlayList/Controller/PlaylistDetailViewController.swift
  16. 4 3
      TSLiveWallpaper/Business/TSMusic/PlayList/Views/PlayDetailListViewCell.swift
  17. 0 2
      TSLiveWallpaper/Business/TSMusic/Search/Controller/LocalSearchViewController.swift
  18. 20 1
      TSLiveWallpaper/Business/TSTabBarController/TSTabBarController.swift
  19. 1 1
      TSLiveWallpaper/Common/Purchase/TSPurchaseManager.swift
  20. BIN
      TSLiveWallpaper/Resource/Example/Example Music.mp3
  21. 76 0
      TSLiveWallpaper/Resource/Example/ExampleIniter.swift

+ 2 - 2
Podfile.lock

@@ -192,11 +192,11 @@ SPEC CHECKSUMS:
   SJVideoPlayer: 4f09814f58522e0975cb2dccfda925f6c8643467
   SnapKit: d612e99e678a2d3b95bf60b0705ed0a35c03484a
   SVProgressHUD: 4837c74bdfe2e51e8821c397825996a8d7de6e22
-  TSVideoKit: 922402ea051d72e78224f22d37c10fdb2e378f60
+  TSVideoKit: 16761d4bf8bb9e8af192459ae9eb01a213fc1531
   TYCyclePagerView: 2b051dade0615c70784aa34f40c646feeddb7344
   TZImagePickerController: d084a7b97c82d387e7669dd86dc9a9057500aacf
   YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30
 
 PODFILE CHECKSUM: db6fcc789e5b50316ea28fb8e59556cae05e1117
 
-COCOAPODS: 1.16.2
+COCOAPODS: 1.15.2

+ 16 - 0
TSLiveWallpaper.xcodeproj/project.pbxproj

@@ -101,6 +101,8 @@
 		60553FDD2D3B84E700BAAD7F /* UIScrollView+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60553FDC2D3B84E700BAAD7F /* UIScrollView+Ext.swift */; };
 		60553FDF2D3B850C00BAAD7F /* TimeInterval+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60553FDE2D3B850C00BAAD7F /* TimeInterval+Ext.swift */; };
 		60553FE32D3DF12200BAAD7F /* CustomSegementItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60553FE22D3DF12200BAAD7F /* CustomSegementItem.swift */; };
+		606372D82D545E6C005C82CF /* Example Music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 606372D72D545E6C005C82CF /* Example Music.mp3 */; };
+		606372DA2D545F0D005C82CF /* ExampleIniter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 606372D92D545F0D005C82CF /* ExampleIniter.swift */; };
 		60F82C0F2D43295100FFB08D /* MusicContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60F82C0E2D43295100FFB08D /* MusicContainerViewController.swift */; };
 		60F82C112D43298800FFB08D /* MusicContainerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60F82C102D43298800FFB08D /* MusicContainerViewModel.swift */; };
 		A81CA4652D15685F00A3AAC8 /* TSLaunchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81CA4642D15685D00A3AAC8 /* TSLaunchVC.swift */; };
@@ -301,6 +303,8 @@
 		60553FDC2D3B84E700BAAD7F /* UIScrollView+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIScrollView+Ext.swift"; sourceTree = "<group>"; };
 		60553FDE2D3B850C00BAAD7F /* TimeInterval+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+Ext.swift"; sourceTree = "<group>"; };
 		60553FE22D3DF12200BAAD7F /* CustomSegementItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSegementItem.swift; sourceTree = "<group>"; };
+		606372D72D545E6C005C82CF /* Example Music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "Example Music.mp3"; sourceTree = "<group>"; };
+		606372D92D545F0D005C82CF /* ExampleIniter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleIniter.swift; sourceTree = "<group>"; };
 		60F82C0E2D43295100FFB08D /* MusicContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicContainerViewController.swift; sourceTree = "<group>"; };
 		60F82C102D43298800FFB08D /* MusicContainerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicContainerViewModel.swift; sourceTree = "<group>"; };
 		71E5F623537702A8306DF3C8 /* Pods-TSLiveWallpaper.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TSLiveWallpaper.release.xcconfig"; path = "Target Support Files/Pods-TSLiveWallpaper/Pods-TSLiveWallpaper.release.xcconfig"; sourceTree = "<group>"; };
@@ -727,6 +731,15 @@
 			path = MusicBase;
 			sourceTree = "<group>";
 		};
+		606372D62D545E55005C82CF /* Example */ = {
+			isa = PBXGroup;
+			children = (
+				606372D72D545E6C005C82CF /* Example Music.mp3 */,
+				606372D92D545F0D005C82CF /* ExampleIniter.swift */,
+			);
+			path = Example;
+			sourceTree = "<group>";
+		};
 		A81CA45F2D1567CD00A3AAC8 /* LaunchVC */ = {
 			isa = PBXGroup;
 			children = (
@@ -920,6 +933,7 @@
 		A81CA4B12D1695F300A3AAC8 /* Resource */ = {
 			isa = PBXGroup;
 			children = (
+				606372D62D545E55005C82CF /* Example */,
 				A81F5B502D19684D00740085 /* Json */,
 				A81CA4B22D1695F800A3AAC8 /* Font */,
 			);
@@ -1249,6 +1263,7 @@
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				606372D82D545E6C005C82CF /* Example Music.mp3 in Resources */,
 				A8C4C0A42D24218A003C46FC /* metadata.mov in Resources */,
 				60553FC42D3B528A00BAAD7F /* IJKPlayer.md in Resources */,
 				A8E56BF92D1520EC003C54AF /* Assets.xcassets in Resources */,
@@ -1350,6 +1365,7 @@
 				A81F5B472D19562800740085 /* EditorVideoControlMaskView.swift in Sources */,
 				A81F5B392D19037800740085 /* TSBaseModel.swift in Sources */,
 				A81CA4A62D16915F00A3AAC8 /* Dictionary+Ex.swift in Sources */,
+				606372DA2D545F0D005C82CF /* ExampleIniter.swift in Sources */,
 				A81CA4AA2D16943800A3AAC8 /* TSMineCell.swift in Sources */,
 				A83946212D1D61D600ABFF0D /* TSRateUsVC.swift in Sources */,
 				A81F5B4F2D19674600740085 /* AVAsset+Ex.swift in Sources */,

+ 5 - 0
TSLiveWallpaper/AppDelegate.swift

@@ -88,6 +88,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
     func applicationDidBecomeActive(_ application: UIApplication) {
         AppDelegate.requestAdTrack()
     }
+    
+    func applicationWillTerminate(_ application: UIApplication) {
+        UserDefaults.standard.setValue(PlayerManager.shared.currentVideo?.videoId ?? "", forKey: "lastedVideoId")
+        UserDefaults.standard.setValue(PlayerManager.shared.currentLoopMode.rawValue, forKey: "lastedPlayMode")
+    }
 }
 
 extension AppDelegate {

BIN
TSLiveWallpaper/Assets.xcassets/.DS_Store


BIN
TSLiveWallpaper/Assets.xcassets/Music/ic_addplaylist.imageset/ic_addplaylist@1x.png


BIN
TSLiveWallpaper/Assets.xcassets/Music/ic_addplaylist.imageset/ic_addplaylist@2x.png


BIN
TSLiveWallpaper/Assets.xcassets/Music/ic_addplaylist.imageset/ic_addplaylist@3x.png


+ 3 - 0
TSLiveWallpaper/Assets.xcassets/Music/ic_default.imageset/Contents.json

@@ -18,5 +18,8 @@
   "info" : {
     "author" : "xcode",
     "version" : 1
+  },
+  "properties" : {
+    "template-rendering-intent" : "original"
   }
 }

+ 12 - 1
TSLiveWallpaper/Business/TSMusic/Custom/PlayMiniBar.swift

@@ -8,10 +8,21 @@
 import Foundation
 import TSVideoKit
 import UIKit
+import MarqueeLabel
 
 class PlayMiniBar: UIView {
     lazy var iconView: UIImageView = .simpleImage(imageName: "ic_default")
-    lazy var titleLabel: UILabel = .simpleLabel(text: "", color: .white)
+    lazy var titleLabel: MarqueeLabel = {
+        let title: MarqueeLabel = .init(frame: CGRect(x: 0, y: 0, width: 300, height: 30))
+        title.trailingBuffer = 20
+        title.animationDelay = 0
+        title.speed = .duration(10)
+        title.font = .systemFont14
+        title.textAlignment = .left
+        title.textColor = .white
+        return title
+    }()
+    
     lazy var bgImageView: UIView = UIView()
     lazy var playButton: UIButton = {
         let btn = UIButton()

+ 1 - 0
TSLiveWallpaper/Business/TSMusic/Detail/PlayerManager.swift

@@ -158,6 +158,7 @@ class PlayerManager {
             /// 发送刷新通知
             NotificationCenter.default.post(name: .K_RefreshNotifaction, object: nil)
         }
+        vc.modalPresentationStyle = .overFullScreen
         PlayerManager.shared.rootVc?.present(vc, animated: true)
     }
 

+ 1 - 1
TSLiveWallpaper/Business/TSMusic/Helper/FilterBarView.swift

@@ -54,7 +54,7 @@ class FilterBarView: UIView {
         let btn = UIButton()
         btn.setTitle("Done".localized(), for: .normal)
         btn.titleLabel?.font = .systemFont(ofSize: 14)
-        btn.setTitleColor(.hexColor("#FFFFFF"), for: .normal)
+        btn.setTitleColor(.hexColor("#60FFD2"), for: .normal)
         btn.isHidden = true
         return btn
     }()

+ 4 - 2
TSLiveWallpaper/Business/TSMusic/List/Controller/MusicContainerViewController.swift

@@ -26,14 +26,14 @@ class MusicContainerViewController: LWBGViewController {
                                         normalFont: .systemFont14,
                                         normalTextColor: .white,
                                         selectedBackgroundColor: .hexColor("#111111"),
-                                        selectedFont: .systemFont14,
+                                        selectedFont: .boldSystemFont14,
                                         selectedTextColor: .black)
         let catalog = CustomSegementItem(text: "Playlist",
                                          normalBackgroundColor: .clear,
                                          normalFont: .systemFont14,
                                          normalTextColor: .white,
                                          selectedBackgroundColor: .hexColor("#111111"),
-                                         selectedFont: .systemFont14,
+                                         selectedFont: .boldSystemFont14,
                                          selectedTextColor: .black)
         let page = BetterSegmentedControl(frame: CGRect(x: 0, y: 0, width: 200, height: 30), segments: [tracks, catalog])
         page.animationDuration = 0
@@ -98,6 +98,8 @@ class MusicContainerViewController: LWBGViewController {
         // 切换到目标视图控制器
         let targetViewController = childVcs[index]
         pageViewController.setViewControllers([targetViewController], direction: direction, animated: true, completion: nil)
+        
+        songlistVc.filterVc.viewModel?.doneMutiSelect()
     }
 
     @objc func showImportMenuView() {

+ 2 - 2
TSLiveWallpaper/Business/TSMusic/List/View/SongListCell.swift

@@ -80,8 +80,8 @@ class SongListCell: UITableViewCell {
         mVideo = video
         self.needOperate = needOperate
         let isPlaying = video.videoId == PlayerManager.shared.currentVideo?.videoId
-        titleLabel.textColor = isPlaying ? .hexColor("#89FC42") : .white
-
+        titleLabel.textColor = isPlaying ? .hexColor("#60FFD2") : .white
+        timeLabel.textColor = isPlaying ? .hexColor("#60FFD2").withAlphaComponent(0.4) : .white.withAlphaComponent(0.4)
         isMuti = isMutiSelected
         titleLabel.text = video.title
         if let artist = video.artist {

+ 1 - 1
TSLiveWallpaper/Business/TSMusic/PlayList/Controller/AddPlayListViewController.swift

@@ -29,7 +29,7 @@ class AddPlayListViewController: LWBaseViewController, UITableViewDelegate {
     lazy var titleLabel: UILabel = .simpleLabel(text: "Add to playlist".localized(), font: .boldSystemFont18, color: .white)
     lazy var closeButton: UIButton = {
         let btn = UIButton()
-        btn.setImage(UIImage(named: "ic_close"), for: .normal)
+        btn.setImage(UIImage(named: "ic-close"), for: .normal)
         btn.addTarget(self, action: #selector(dismissCurrent), for: .touchUpInside)
         return btn
     }()

+ 3 - 2
TSLiveWallpaper/Business/TSMusic/PlayList/Controller/PlaylistDetailViewController.swift

@@ -124,6 +124,7 @@ class PlaylistDetailViewController: LWBGViewController, UITableViewDelegate {
 
     override func viewWillDisappear(_ animated: Bool) {
         super.viewWillDisappear(animated)
+        filterVc.viewModel?.doneMutiSelect()
     }
 
     override func addNotifaction() {
@@ -318,14 +319,14 @@ extension PlaylistDetailViewController: FilterBarViewControllerDelegate {
     func resetViews() {
         listView.snp.updateConstraints { make in
             if viewModel?.isMuti == true {
-                make.bottom.equalToSuperview().offset(-180)
+                make.bottom.equalToSuperview().offset(-(k_TabBar_Height + 62))
             } else {
                 make.bottom.equalToSuperview()
             }
         }
         emptyView.snp.updateConstraints { make in
             if viewModel?.isMuti == true {
-                make.bottom.equalToSuperview().offset(-180)
+                make.bottom.equalToSuperview().offset(-(k_TabBar_Height + 62))
             } else {
                 make.bottom.equalToSuperview()
             }

+ 4 - 3
TSLiveWallpaper/Business/TSMusic/PlayList/Views/PlayDetailListViewCell.swift

@@ -40,7 +40,7 @@ class PlayDetailListViewCell: UITableViewCell {
 
     lazy var deleteButton: UIButton = {
         let btn = UIButton()
-        btn.setImage(.init(named: "ic_close"), for: .normal)
+        btn.setImage(.init(named: "ic-close"), for: .normal)
         btn.addTarget(self, action: #selector(deleteButtonAction), for: .touchUpInside)
         return btn
     }()
@@ -60,7 +60,8 @@ class PlayDetailListViewCell: UITableViewCell {
         titleLabel.text = video.title
         detailLabel.text = video.artist
         let isPlaying = video.videoId == PlayerManager.shared.currentVideo?.videoId
-        playingTag.isHidden = !isPlaying
+        titleLabel.textColor = isPlaying ? .hexColor("#60FFD2") : .white
+        detailLabel.textColor = isPlaying ? .hexColor("#60FFD2").withAlphaComponent(0.4) : .white.withAlphaComponent(0.4)
 
         if video.isOnline {
             iconView.kf.setImage(with: video.iconUrl)
@@ -124,7 +125,7 @@ class PlayDetailListViewCell: UITableViewCell {
         deleteButton.snp.makeConstraints { make in
             make.trailing.equalToSuperview().offset(-16)
             make.centerY.equalToSuperview()
-            make.width.height.equalTo(24)
+            make.width.height.equalTo(18)
         }
     }
 }

+ 0 - 2
TSLiveWallpaper/Business/TSMusic/Search/Controller/LocalSearchViewController.swift

@@ -22,12 +22,10 @@ class LocalSearchViewController: LWBGViewController {
     lazy var searchBar: CWSearchTextBar = {
         let bar = CWSearchTextBar()
         bar.textFiled.delegate = self
-        bar.backgroundColor = .white.withAlphaComponent(0.1)
         bar.textFiled.textColor = .white
         bar.textFiled.attributedPlaceholder = NSAttributedString(string: "Search Music".localized(), attributes: [
             .foregroundColor: UIColor.hexColor("#FFFFFF").withAlphaComponent(0.4),
             .font: UIFont.systemFont(ofSize: 14)])
-        bar.customCornerRadius = 8
         return bar
     }()
 

+ 20 - 1
TSLiveWallpaper/Business/TSTabBarController/TSTabBarController.swift

@@ -6,6 +6,7 @@
 //
 
 import UIKit
+import TSVideoKit
 
 class TSTabBarController: UITabBarController {
         
@@ -41,6 +42,7 @@ class TSTabBarController: UITabBarController {
         delegate = self
         createUI()
         setUpData()
+        initExampleData()
     }
 
     @objc private func setUpData() {
@@ -128,6 +130,23 @@ class TSTabBarController: UITabBarController {
         debugPrint("TSTabBarController deinit")
         NotificationCenter.default.removeObserver(self)
     }
+    
+    func initExampleData() {
+        if UserDefaults.standard.string(forKey: "InitExampleData") == nil {
+            if let path = Bundle.main.path(forResource: "Example Music", ofType: ".mp3") {
+                let fileUrl = URL(fileURLWithPath: path)
+                ExampleIniter.default.copyFileToUrl(url: fileUrl)
+                UserDefaults.standard.set("1", forKey: "InitExampleData")
+            }
+
+            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
+                if let firstVideo = TSVideoOperator.shared.dataManager.fetchAllVideos().first {
+                    TSVideoOperator.shared.playerViewModel.currentVideo = firstVideo
+                    PlayerManager.shared.miniBar.updateVideoInfo(video: firstVideo, state: .pause)
+                }
+            }
+        }
+    }
 }
 
 extension TSTabBarController: UITabBarControllerDelegate {
@@ -169,7 +188,7 @@ extension TSTabBarController {
         multiSelectView.snp.makeConstraints { make in
             make.bottom.equalToSuperview()
             make.leading.trailing.equalToSuperview()
-            make.top.equalTo(miniBar.snp.top)
+            make.height.equalTo(k_Height_TabBar + 62)
         }
     }
 

+ 1 - 1
TSLiveWallpaper/Common/Purchase/TSPurchaseManager.swift

@@ -112,7 +112,7 @@ public class PurchaseManager: NSObject {
 
     public var expiredDateString: String {
         if vipType == .lifetime{
-            return "LifeTime"
+            return "Lifetime"
         } else {
             if let expDate = expiredDate {
                 let format = DateFormatter()

BIN
TSLiveWallpaper/Resource/Example/Example Music.mp3


+ 76 - 0
TSLiveWallpaper/Resource/Example/ExampleIniter.swift

@@ -0,0 +1,76 @@
+//
+//  ExampleIniter.swift
+//  TSLiveWallpaper
+//
+//  Created by nkl on 2025/2/6.
+//
+
+import Foundation
+import TSVideoKit
+
+class ExampleIniter {
+    static let `default` = ExampleIniter()
+
+    private func uniqueFileURL(at directory: URL, originalURL: URL) -> URL {
+        let fileManager = FileManager.default
+
+        // 检查目录是否存在,如果不存在则创建目录
+        if !fileManager.fileExists(atPath: directory.path) {
+            do {
+                try fileManager.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil)
+            } catch {
+                // 这里可以选择抛出错误或处理错误
+            }
+        }
+
+        let originalFilename = originalURL.deletingPathExtension().lastPathComponent
+        let fileExtension = originalURL.pathExtension
+        var uniqueURL = directory.appendingPathComponent(originalFilename).appendingPathExtension(fileExtension)
+
+        var counter = 1
+        while fileManager.fileExists(atPath: uniqueURL.path) {
+            uniqueURL = directory.appendingPathComponent("\(originalFilename)-\(counter)").appendingPathExtension(fileExtension)
+            counter += 1
+        }
+
+        return uniqueURL
+    }
+
+    func copyFileToUrl(url: URL) {
+        let fileId = UUID().uuidString
+        let path = TSVideoOperator.shared.configuration.fileDir.appendingPathComponent(fileId)
+        let destinationURL = uniqueFileURL(at: path, originalURL: url)
+        do {
+            try FileManager.default.copyItem(at: url, to: destinationURL)
+            Task {
+                await self.importVideo(videoId: fileId, from: destinationURL)
+            }
+
+        } catch {
+            print(error.localizedDescription)
+        }
+    }
+
+    private func importVideo(videoId: String, from url: URL) async {
+        let asset = AVAsset(url: url)
+        let image = await asset.generateThumbnail()
+
+        await MainActor.run {
+            let title = url.lastPathComponent
+            let pathExt = url.pathExtension.lowercased()
+            let vPath = videoId + "/" + title
+
+            let audios = ["mp3", "wav", "m4a"]
+            var isRing: Bool = false
+            if audios.contains(pathExt) {
+                isRing = true
+            }
+            let imageData = image?.jpegData(compressionQuality: 0.8)
+            let defaultData = UIImage(named: "ic_default")?.jpegData(compressionQuality: 0.8)
+            let finalData = imageData ?? defaultData
+            TSVideoOperator.shared.dataManager.createVideo(videoId: videoId, videoUrl: nil, audioStream: nil, videoStream: nil, videoTitle: title, artist: "UnKnown".localized(), artwork: finalData, online: false, customTag: isRing, status: .cached, vPath: vPath) { _ in
+                NotificationCenter.default.post(name: kDataChangedNotifactionName, object: nil)
+            }
+        }
+    }
+}