From f05eee3593e9566320e219389cac20517a6383c6 Mon Sep 17 00:00:00 2001 From: Stephen Byatt <47413006+stephenb10@users.noreply.github.com> Date: Tue, 22 Jun 2021 14:18:01 +1000 Subject: [PATCH] Move duplicate objects in both Video Players to a shared file --- .../VideoPlayerViewController.swift | 19 ------------ JellyfinPlayer.xcodeproj/project.pbxproj | 6 ++++ JellyfinPlayer/VideoPlayer.swift | 17 ----------- Shared/ViewModels/VideoPlayerModel.swift | 29 +++++++++++++++++++ 4 files changed, 35 insertions(+), 36 deletions(-) create mode 100644 Shared/ViewModels/VideoPlayerModel.swift diff --git a/JellyfinPlayer tvOS/VideoPlayer/VideoPlayerViewController.swift b/JellyfinPlayer tvOS/VideoPlayer/VideoPlayerViewController.swift index 200961e9..3a4b8bff 100644 --- a/JellyfinPlayer tvOS/VideoPlayer/VideoPlayerViewController.swift +++ b/JellyfinPlayer tvOS/VideoPlayer/VideoPlayerViewController.swift @@ -11,24 +11,6 @@ import MediaPlayer import JellyfinAPI import Combine -struct Subtitle { - var name: String - var id: Int32 - var url: URL? - var delivery: SubtitleDeliveryMethod - var codec: String -} - -struct AudioTrack { - var name: String - var id: Int32 -} - -class PlaybackItem: ObservableObject { - @Published var videoType: PlayMethod = .directPlay - @Published var videoUrl: URL = URL(string: "https://example.com")! -} - protocol VideoPlayerSettingsDelegate: AnyObject { func selectNew(audioTrack id: Int32) func selectNew(subtitleTrack id: Int32) @@ -167,7 +149,6 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate, let playbackInfo = PlaybackInfoDto(userId: SessionManager.current.user.user_id!, maxStreamingBitrate: Int(maxBitrate), startTimeTicks: manifest.userData?.playbackPositionTicks ?? 0, deviceProfile: profile, autoOpenLiveStream: true) DispatchQueue.global(qos: .userInitiated).async { [self] in - // delegate?.showLoadingView(self) MediaInfoAPI.getPostedPlaybackInfo(itemId: manifest.id!, userId: SessionManager.current.user.user_id!, maxStreamingBitrate: Int(maxBitrate), startTimeTicks: manifest.userData?.playbackPositionTicks ?? 0, autoOpenLiveStream: true, playbackInfoDto: playbackInfo) .sink(receiveCompletion: { result in print(result) diff --git a/JellyfinPlayer.xcodeproj/project.pbxproj b/JellyfinPlayer.xcodeproj/project.pbxproj index 86b882cb..1662a1be 100644 --- a/JellyfinPlayer.xcodeproj/project.pbxproj +++ b/JellyfinPlayer.xcodeproj/project.pbxproj @@ -15,6 +15,8 @@ 09389CC326814DF600AE350E /* VideoPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09389CBC26814DF600AE350E /* VideoPlayerViewController.swift */; }; 09389CC426814DF600AE350E /* AudioView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09389CBD26814DF600AE350E /* AudioView.swift */; }; 09389CC526814E4500AE350E /* DeviceProfileBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53192D5C265AA78A008A4215 /* DeviceProfileBuilder.swift */; }; + 09389CC726819B4600AE350E /* VideoPlayerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09389CC626819B4500AE350E /* VideoPlayerModel.swift */; }; + 09389CC826819B4600AE350E /* VideoPlayerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09389CC626819B4500AE350E /* VideoPlayerModel.swift */; }; 531690E5267ABD5C005D8AB9 /* MainTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 531690E4267ABD5C005D8AB9 /* MainTabView.swift */; }; 531690E7267ABD79005D8AB9 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 531690E6267ABD79005D8AB9 /* HomeView.swift */; }; 531690ED267ABF46005D8AB9 /* ContinueWatchingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 531690EB267ABF46005D8AB9 /* ContinueWatchingView.swift */; }; @@ -196,6 +198,7 @@ 09389CBB26814DF600AE350E /* VideoPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoPlayer.swift; sourceTree = ""; }; 09389CBC26814DF600AE350E /* VideoPlayerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoPlayerViewController.swift; sourceTree = ""; }; 09389CBD26814DF600AE350E /* AudioView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AudioView.swift; sourceTree = ""; }; + 09389CC626819B4500AE350E /* VideoPlayerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlayerModel.swift; sourceTree = ""; }; 3773C07648173CE7FEC083D5 /* Pods-JellyfinPlayer iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JellyfinPlayer iOS.debug.xcconfig"; path = "Target Support Files/Pods-JellyfinPlayer iOS/Pods-JellyfinPlayer iOS.debug.xcconfig"; sourceTree = ""; }; 3F905C1D3D3A0C9E13E7A0BC /* Pods_JellyfinPlayer_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_JellyfinPlayer_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 531690E4267ABD5C005D8AB9 /* MainTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabView.swift; sourceTree = ""; }; @@ -393,6 +396,7 @@ 62E632EB267D410B0063E547 /* SeriesItemViewModel.swift */, 62E632EE267D43320063E547 /* LibraryFilterViewModel.swift */, 62E632F2267D54030063E547 /* DetailItemViewModel.swift */, + 09389CC626819B4500AE350E /* VideoPlayerModel.swift */, ); path = ViewModels; sourceTree = ""; @@ -939,6 +943,7 @@ 531690FA267AD6EC005D8AB9 /* PlainNavigationLinkButton.swift in Sources */, 535870A32669D89F00D05A09 /* Model.xcdatamodeld in Sources */, 09389CC426814DF600AE350E /* AudioView.swift in Sources */, + 09389CC826819B4600AE350E /* VideoPlayerModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -995,6 +1000,7 @@ 625CB56C2678C0FD00530A6E /* MainTabView.swift in Sources */, 539B2DA5263BA5B8007FF1A4 /* SettingsView.swift in Sources */, 5338F74E263B61370014BF09 /* ConnectToServerView.swift in Sources */, + 09389CC726819B4600AE350E /* VideoPlayerModel.swift in Sources */, 53AD124D267029D60094A276 /* SeriesItemView.swift in Sources */, 5377CBF5263B596A003A4E83 /* JellyfinPlayerApp.swift in Sources */, 53EE24E6265060780068F029 /* LibrarySearchView.swift in Sources */, diff --git a/JellyfinPlayer/VideoPlayer.swift b/JellyfinPlayer/VideoPlayer.swift index 73137cd0..4aadc9ad 100644 --- a/JellyfinPlayer/VideoPlayer.swift +++ b/JellyfinPlayer/VideoPlayer.swift @@ -13,29 +13,12 @@ import Combine import GoogleCast import SwiftyJSON -struct Subtitle { - var name: String - var id: Int32 - var url: URL? - var delivery: SubtitleDeliveryMethod - var codec: String -} - -struct AudioTrack { - var name: String - var id: Int32 -} enum PlayerDestination { case remote case local } -class PlaybackItem: ObservableObject { - @Published var videoType: PlayMethod = .directPlay - @Published var videoUrl: URL = URL(string: "https://example.com")! -} - protocol PlayerViewControllerDelegate: AnyObject { func hideLoadingView(_ viewController: PlayerViewController) func showLoadingView(_ viewController: PlayerViewController) diff --git a/Shared/ViewModels/VideoPlayerModel.swift b/Shared/ViewModels/VideoPlayerModel.swift new file mode 100644 index 00000000..cb219a0d --- /dev/null +++ b/Shared/ViewModels/VideoPlayerModel.swift @@ -0,0 +1,29 @@ +// + /* + * SwiftFin is subject to the terms of the Mozilla Public + * License, v2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * Copyright 2021 Aiden Vigue & Jellyfin Contributors + */ + +import SwiftUI +import JellyfinAPI + +struct Subtitle { + var name: String + var id: Int32 + var url: URL? + var delivery: SubtitleDeliveryMethod + var codec: String +} + +struct AudioTrack { + var name: String + var id: Int32 +} + +class PlaybackItem: ObservableObject { + @Published var videoType: PlayMethod = .directPlay + @Published var videoUrl: URL = URL(string: "https://example.com")! +}