Skip to content

Commit ad8be7d

Browse files
committed
v1.4.2(53)
Fix player bug
1 parent b1d657b commit ad8be7d

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

ccViewer/CryptCloudViewer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@
813813
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
814814
CODE_SIGN_ENTITLEMENTS = ccViewer/ccViewer.entitlements;
815815
CODE_SIGN_STYLE = Automatic;
816-
CURRENT_PROJECT_VERSION = 52;
816+
CURRENT_PROJECT_VERSION = 53;
817817
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES;
818818
DEVELOPMENT_TEAM = 7A9X38B4YU;
819819
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
@@ -828,7 +828,7 @@
828828
"$(inherited)",
829829
"@executable_path/Frameworks",
830830
);
831-
MARKETING_VERSION = 1.4.1;
831+
MARKETING_VERSION = 1.4.2;
832832
OTHER_LDFLAGS = (
833833
"-ObjC",
834834
"-lc++",
@@ -848,7 +848,7 @@
848848
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
849849
CODE_SIGN_ENTITLEMENTS = ccViewer/ccViewer.entitlements;
850850
CODE_SIGN_STYLE = Automatic;
851-
CURRENT_PROJECT_VERSION = 52;
851+
CURRENT_PROJECT_VERSION = 53;
852852
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES;
853853
DEVELOPMENT_TEAM = 7A9X38B4YU;
854854
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
@@ -863,7 +863,7 @@
863863
"$(inherited)",
864864
"@executable_path/Frameworks",
865865
);
866-
MARKETING_VERSION = 1.4.1;
866+
MARKETING_VERSION = 1.4.2;
867867
OTHER_LDFLAGS = (
868868
"-ObjC",
869869
"-lc++",

ccViewer/ccViewer/CustomPlayerViewController.swift

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class CustomPlayerView: NSObject, AVPlayerViewControllerDelegate {
5050
var customDelegate = [URL: [CustomAVARLDelegate]]()
5151
var infoItems = [URL: [String: Any]]()
5252
var image: MPMediaItemArtwork?
53+
var playCount = -1
5354

5455
func getURL(storage: String, fileId: String) -> URL {
5556
var allowedCharacterSet = CharacterSet.alphanumerics
@@ -100,6 +101,9 @@ class CustomPlayerView: NSObject, AVPlayerViewControllerDelegate {
100101
}
101102
return playitem
102103
})
104+
if !self.loop {
105+
playCount = items.count
106+
}
103107
var player = AVQueuePlayer(items: items)
104108
return player
105109
}()
@@ -181,10 +185,12 @@ class CustomPlayerView: NSObject, AVPlayerViewControllerDelegate {
181185
}
182186

183187
func skipNextTrack() {
184-
let url = (player.currentItem?.asset as? AVURLAsset)?.url
188+
print("skipNextTrack ", playCount)
189+
print(player.items())
190+
let url = prevURL
185191
player.pause()
186192
if player.items().count <= 2 {
187-
if loop {
193+
if loop || UserDefaults.standard.bool(forKey: "keepOpenWhenDone") {
188194
loopSetup()
189195
}
190196
}
@@ -216,7 +222,15 @@ class CustomPlayerView: NSObject, AVPlayerViewControllerDelegate {
216222
customDelegate.removeValue(forKey: url)
217223
}
218224
}
219-
player.play()
225+
if playCount <= 1 {
226+
playCount = playItems.count
227+
}
228+
else {
229+
player.play()
230+
if playCount > 0 {
231+
playCount -= 1
232+
}
233+
}
220234
}
221235
}
222236

@@ -275,6 +289,13 @@ class CustomPlayerView: NSObject, AVPlayerViewControllerDelegate {
275289
}
276290

277291
func play(parent: UIViewController) {
292+
do {
293+
try AVAudioSession.sharedInstance().setCategory(.playback)
294+
try AVAudioSession.sharedInstance().setActive(true)
295+
} catch {
296+
print(error)
297+
}
298+
278299
playerViewController.player = player
279300
playerViewController.updatesNowPlayingInfoCenter = false
280301

@@ -412,17 +433,14 @@ class CustomPlayerView: NSObject, AVPlayerViewControllerDelegate {
412433
}
413434

414435
func nextTrack() {
415-
let url = prevURL
416-
var reload = UserDefaults.standard.bool(forKey: "keepOpenWhenDone")
417-
if reload && player.items().count > 1 {
418-
reload = false
436+
print("nextTrack ", playCount)
437+
print(player.items())
438+
if playCount > 0 {
439+
playCount -= 1
419440
}
441+
let url = prevURL
420442
if player.items().count <= 2 {
421-
if loop {
422-
reload = false
423-
loopSetup()
424-
}
425-
if reload {
443+
if loop || UserDefaults.standard.bool(forKey: "keepOpenWhenDone") {
426444
loopSetup()
427445
}
428446
}
@@ -454,8 +472,9 @@ class CustomPlayerView: NSObject, AVPlayerViewControllerDelegate {
454472
}
455473
}
456474
}
457-
if reload {
475+
if playCount == 0 {
458476
player.pause()
477+
playCount = playItems.count
459478
}
460479
}
461480

0 commit comments

Comments
 (0)