diff --git a/components/app/AudioPlayer.vue b/components/app/AudioPlayer.vue index 50ad3e6a..6327188e 100644 --- a/components/app/AudioPlayer.vue +++ b/components/app/AudioPlayer.vue @@ -687,7 +687,6 @@ export default { }) }, onPlaybackClosed() { - console.log('Received onPlaybackClosed evt') this.endPlayback() }, onPlaybackFailed(data) { @@ -717,14 +716,18 @@ export default { }, mounted() { this.updateScreenSize() - screen.orientation.addEventListener('change', this.screenOrientationChange) + if (screen.orientation) { + screen.orientation.addEventListener('change', this.screenOrientationChange) + } document.body.addEventListener('touchstart', this.touchstart) document.body.addEventListener('touchend', this.touchend) document.body.addEventListener('touchmove', this.touchmove) this.$nextTick(this.init) }, beforeDestroy() { - screen.orientation.removeEventListener('change', this.screenOrientationChange) + if (screen.orientation) { + screen.orientation.removeEventListener('change', this.screenOrientationChange) + } if (this.playbackSession) { console.log('[AudioPlayer] Before destroy closing playback') @@ -752,7 +755,6 @@ export default { --cover-image-height: 0px; --cover-image-width-collapsed: 60px; --cover-image-height-collapsed: 60px; - --test-var: 100px; } .bookCoverWrapper { box-shadow: 3px -2px 5px #00000066; diff --git a/components/app/SideDrawer.vue b/components/app/SideDrawer.vue index 9a62c7e8..28660b7c 100644 --- a/components/app/SideDrawer.vue +++ b/components/app/SideDrawer.vue @@ -108,12 +108,12 @@ export default { text: 'Local Media', to: '/localMedia/folders' }) - items.push({ - icon: 'settings', - text: 'Settings', - to: '/settings' - }) } + items.push({ + icon: 'settings', + text: 'Settings', + to: '/settings' + }) return items }, currentRoutePath() { diff --git a/ios/App/App.xcodeproj/project.pbxproj b/ios/App/App.xcodeproj/project.pbxproj index b7c77666..1de6407c 100644 --- a/ios/App/App.xcodeproj/project.pbxproj +++ b/ios/App/App.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 4D66B954282EE87C008272D4 /* AbsDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D66B953282EE87C008272D4 /* AbsDownloader.swift */; }; 4D66B956282EE951008272D4 /* AbsFileSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D66B955282EE951008272D4 /* AbsFileSystem.m */; }; 4D66B958282EEA14008272D4 /* AbsFileSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D66B957282EEA14008272D4 /* AbsFileSystem.swift */; }; + 4DF74912287105C600AC7814 /* DeviceSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF74911287105C600AC7814 /* DeviceSettings.swift */; }; 50379B232058CBB4000EE86E /* capacitor.config.json in Resources */ = {isa = PBXBuildFile; fileRef = 50379B222058CBB4000EE86E /* capacitor.config.json */; }; 504EC3081FED79650016851F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504EC3071FED79650016851F /* AppDelegate.swift */; }; 504EC30D1FED79650016851F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 504EC30B1FED79650016851F /* Main.storyboard */; }; @@ -59,6 +60,7 @@ 4D66B955282EE951008272D4 /* AbsFileSystem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AbsFileSystem.m; sourceTree = ""; }; 4D66B957282EEA14008272D4 /* AbsFileSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AbsFileSystem.swift; sourceTree = ""; }; 4D8D412C26E187E400BA5F0D /* App-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "App-Bridging-Header.h"; sourceTree = ""; }; + 4DF74911287105C600AC7814 /* DeviceSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceSettings.swift; sourceTree = ""; }; 50379B222058CBB4000EE86E /* capacitor.config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = capacitor.config.json; sourceTree = ""; }; 504EC3041FED79650016851F /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; }; 504EC3071FED79650016851F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -134,6 +136,7 @@ 3ABF580828059BAE005DFBE5 /* PlaybackSession.swift */, C4D0677428106D0C00B8F875 /* DataClasses.swift */, 3A90295E280968E700E1D427 /* PlaybackReport.swift */, + 4DF74911287105C600AC7814 /* DeviceSettings.swift */, ); path = models; sourceTree = ""; @@ -325,6 +328,7 @@ 3AD4FCEB280443DD006DB301 /* Database.swift in Sources */, 3AD4FCE528043E50006DB301 /* AbsDatabase.swift in Sources */, 4D66B952282EE822008272D4 /* AbsDownloader.m in Sources */, + 4DF74912287105C600AC7814 /* DeviceSettings.swift in Sources */, 3AF197102806E3DC0096F747 /* AbsAudioPlayer.m in Sources */, 3AF1970C2806E2590096F747 /* ApiClient.swift in Sources */, C4D0677528106D0C00B8F875 /* DataClasses.swift in Sources */, diff --git a/ios/App/App/plugins/AbsAudioPlayer.swift b/ios/App/App/plugins/AbsAudioPlayer.swift index 5b6f21a1..965c1306 100644 --- a/ios/App/App/plugins/AbsAudioPlayer.swift +++ b/ios/App/App/plugins/AbsAudioPlayer.swift @@ -43,10 +43,10 @@ public class AbsAudioPlayer: CAPPlugin { initialPlayWhenReady = playWhenReady initialPlaybackRate = playbackRate + PlayerHandler.stopPlayback() + sendPrepareMetadataEvent(itemId: libraryItemId!, playWhenReady: playWhenReady) ApiClient.startPlaybackSession(libraryItemId: libraryItemId!, episodeId: episodeId, forceTranscode: false) { session in - PlayerHandler.startPlayback(session: session, playWhenReady: playWhenReady, playbackRate: playbackRate) - do { self.sendPlaybackSession(session: try session.asDictionary()) call.resolve(try session.asDictionary()) @@ -56,6 +56,8 @@ public class AbsAudioPlayer: CAPPlugin { call.resolve([:]) } + + PlayerHandler.startPlayback(session: session, playWhenReady: playWhenReady, playbackRate: playbackRate) self.sendMetadata() } } @@ -173,7 +175,7 @@ public class AbsAudioPlayer: CAPPlugin { let playbackSession = PlayerHandler.getPlaybackSession() let libraryItemId = playbackSession?.libraryItemId ?? "" let episodeId = playbackSession?.episodeId ?? nil - NSLog("TEST: Forcing Transcode") + NSLog("Forcing Transcode") // If direct playing then fallback to transcode ApiClient.startPlaybackSession(libraryItemId: libraryItemId, episodeId: episodeId, forceTranscode: true) { session in diff --git a/ios/App/App/plugins/AbsDatabase.m b/ios/App/App/plugins/AbsDatabase.m index aa89aecd..e948a11a 100644 --- a/ios/App/App/plugins/AbsDatabase.m +++ b/ios/App/App/plugins/AbsDatabase.m @@ -19,5 +19,6 @@ CAP_PLUGIN(AbsDatabase, "AbsDatabase", CAP_PLUGIN_METHOD(getLocalLibraryItem, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(getLocalLibraryItemByLLId, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(getLocalLibraryItemsInFolder, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(updateDeviceSettings, CAPPluginReturnPromise); ) diff --git a/ios/App/App/plugins/AbsDatabase.swift b/ios/App/App/plugins/AbsDatabase.swift index 99a403e9..673f002e 100644 --- a/ios/App/App/plugins/AbsDatabase.swift +++ b/ios/App/App/plugins/AbsDatabase.swift @@ -65,11 +65,12 @@ public class AbsDatabase: CAPPlugin { @objc func getDeviceData(_ call: CAPPluginCall) { let configs = Database.shared.getServerConnectionConfigs() let index = Database.shared.getLastActiveConfigIndex() + let settings = Database.shared.getDeviceSettings() call.resolve([ "serverConnectionConfigs": configs.map { config in convertServerConnectionConfigToJSON(config: config) }, "lastServerConnectionConfigId": configs.first { config in config.index == index }?.id as Any, - // "currentLocalPlaybackSession": nil, + "deviceSettings": deviceSettingsToJSON(settings: settings) ]) } @@ -85,4 +86,18 @@ public class AbsDatabase: CAPPlugin { @objc func getLocalLibraryItemsInFolder(_ call: CAPPluginCall) { call.resolve([ "value": [] ]) } + @objc func updateDeviceSettings(_ call: CAPPluginCall) { + let disableAutoRewind = call.getBool("disableAutoRewind") ?? false + let jumpBackwardsTime = call.getInt("jumpBackwardsTime") ?? 10 + let jumpForwardTime = call.getInt("jumpForwardTime") ?? 10 + let settings = DeviceSettings() + settings.disableAutoRewind = disableAutoRewind + settings.jumpBackwardsTime = jumpBackwardsTime + settings.jumpForwardTime = jumpForwardTime + + Database.shared.setDeviceSettings(deviceSettings: settings) + +// call.resolve([ "value": [] ]) + getDeviceData(call) + } } diff --git a/ios/App/Podfile b/ios/App/Podfile index 89125e80..dcdae730 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -9,12 +9,12 @@ install! 'cocoapods', :disable_input_output_paths => true def capacitor_pods pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' - pod 'CapacitorApp', :path => '..\..\node_modules\@capacitor\app' - pod 'CapacitorDialog', :path => '..\..\node_modules\@capacitor\dialog' - pod 'CapacitorHaptics', :path => '..\..\node_modules\@capacitor\haptics' - pod 'CapacitorNetwork', :path => '..\..\node_modules\@capacitor\network' - pod 'CapacitorStatusBar', :path => '..\..\node_modules\@capacitor\status-bar' - pod 'CapacitorStorage', :path => '..\..\node_modules\@capacitor\storage' + pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app' + pod 'CapacitorDialog', :path => '../../node_modules/@capacitor/dialog' + pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics' + pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network' + pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar' + pod 'CapacitorStorage', :path => '../../node_modules/@capacitor/storage' end target 'App' do diff --git a/ios/App/Shared/models/DeviceSettings.swift b/ios/App/Shared/models/DeviceSettings.swift new file mode 100644 index 00000000..9fafa2aa --- /dev/null +++ b/ios/App/Shared/models/DeviceSettings.swift @@ -0,0 +1,33 @@ +// +// DeviceSettings.swift +// App +// +// Created by advplyr on 7/2/22. +// + +import Foundation +import RealmSwift + +class DeviceSettings: Object { + @Persisted var disableAutoRewind: Bool + @Persisted var jumpBackwardsTime: Int + @Persisted var jumpForwardTime: Int +} + +func getDefaultDeviceSettings() -> DeviceSettings { + let settings = DeviceSettings() + settings.disableAutoRewind = false + settings.jumpForwardTime = 10 + settings.jumpBackwardsTime = 10 + return settings +} + +func deviceSettingsToJSON(settings: DeviceSettings) -> Dictionary { + return Database.realmQueue.sync { + return [ + "disableAutoRewind": settings.disableAutoRewind, + "jumpBackwardsTime": settings.jumpBackwardsTime, + "jumpForwardTime": settings.jumpForwardTime + ] + } +} diff --git a/ios/App/Shared/player/AudioPlayer.swift b/ios/App/Shared/player/AudioPlayer.swift index 64aeff1e..b6f8a7da 100644 --- a/ios/App/Shared/player/AudioPlayer.swift +++ b/ios/App/Shared/player/AudioPlayer.swift @@ -66,10 +66,10 @@ class AudioPlayer: NSObject { } self.currentTrackIndex = getItemIndexForTime(time: playbackSession.currentTime) - NSLog("TEST: Starting track index \(self.currentTrackIndex) for start time \(playbackSession.currentTime)") + NSLog("Starting track index \(self.currentTrackIndex) for start time \(playbackSession.currentTime)") let playerItems = self.allPlayerItems[self.currentTrackIndex.. 0.0 && !(observed && rate == 1) { @@ -373,7 +373,7 @@ class AudioPlayer: NSObject { public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if context == &playerContext { if keyPath == #keyPath(AVPlayer.rate) { - NSLog("TEST: playerContext observer player rate") + NSLog("playerContext observer player rate") self.setPlaybackRate(change?[.newKey] as? Float ?? 1.0, observed: true) } else if keyPath == #keyPath(AVPlayer.currentItem) { NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.update.rawValue), object: nil) diff --git a/ios/App/Shared/util/Database.swift b/ios/App/Shared/util/Database.swift index 1c528dfe..f2276336 100644 --- a/ios/App/Shared/util/Database.swift +++ b/ios/App/Shared/util/Database.swift @@ -128,4 +128,24 @@ class Database { return instance.objects(ServerConnectionConfigActiveIndex.self).first?.index ?? nil } } + public func setDeviceSettings(deviceSettings: DeviceSettings) { + Database.realmQueue.sync { + let existing = instance.objects(DeviceSettings.self) + + do { + try instance.write { + instance.delete(existing) + instance.add(deviceSettings) + } + } catch(let exception) { + NSLog("failed to save device settings") + debugPrint(exception) + } + } + } + public func getDeviceSettings() -> DeviceSettings { + return Database.realmQueue.sync { + return instance.objects(DeviceSettings.self).first ?? getDefaultDeviceSettings() + } + } } diff --git a/pages/settings.vue b/pages/settings.vue index 9c950f5a..4c703ba5 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -1,6 +1,6 @@