Split VideoPlayerManagers (#875)

This commit is contained in:
Daniel Chick 2023-10-12 21:27:31 -05:00 committed by GitHub
parent 289868e71a
commit 043a95de00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 59 deletions

View File

@ -0,0 +1,47 @@
//
// 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 (c) 2023 Jellyfin & Jellyfin Contributors
//
import Foundation
import JellyfinAPI
class DownloadVideoPlayerManager: VideoPlayerManager {
init(downloadTask: DownloadTask) {
super.init()
guard let playbackURL = downloadTask.getMediaURL() else {
logger.error("Download task does not have media url for item: \(downloadTask.item.displayTitle)")
return
}
self.currentViewModel = .init(
playbackURL: playbackURL,
item: downloadTask.item,
mediaSource: .init(),
playSessionID: "",
videoStreams: downloadTask.item.videoStreams,
audioStreams: downloadTask.item.audioStreams,
subtitleStreams: downloadTask.item.subtitleStreams,
selectedAudioStreamIndex: 1,
selectedSubtitleStreamIndex: 1,
chapters: downloadTask.item.fullChapterInfo,
streamType: .direct
)
}
override func getAdjacentEpisodes(for item: BaseItemDto) {}
override func sendStartReport() {}
override func sendPauseReport() {}
override func sendStopReport() {}
override func sendProgressReport() {}
}

View File

@ -0,0 +1,25 @@
//
// 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 (c) 2023 Jellyfin & Jellyfin Contributors
//
import Foundation
import JellyfinAPI
class OnlineVideoPlayerManager: VideoPlayerManager {
init(item: BaseItemDto, mediaSource: MediaSourceInfo) {
super.init()
Task {
let viewModel = try await item.videoPlayerViewModel(with: mediaSource)
await MainActor.run {
self.currentViewModel = viewModel
}
}
}
}

View File

@ -174,7 +174,7 @@ class VideoPlayerManager: ViewModel {
currentProgressWorkItem?.cancel()
print("sent start report")
logger.debug("sent start report")
Task {
let startInfo = PlaybackStartInfo(
@ -206,7 +206,7 @@ class VideoPlayerManager: ViewModel {
guard Defaults[.sendProgressReports] else { return }
#endif
print("sent stop report")
logger.debug("sent stop report")
currentProgressWorkItem?.cancel()
@ -229,7 +229,7 @@ class VideoPlayerManager: ViewModel {
guard Defaults[.sendProgressReports] else { return }
#endif
print("sent pause report")
logger.debug("sent pause report")
currentProgressWorkItem?.cancel()
@ -278,61 +278,7 @@ class VideoPlayerManager: ViewModel {
let request = Paths.reportPlaybackProgress(progressInfo)
let _ = try await userSession.client.send(request)
print("sent progress task")
logger.debug("sent progress task")
}
}
}
// TODO: move to own file
class OnlineVideoPlayerManager: VideoPlayerManager {
init(item: BaseItemDto, mediaSource: MediaSourceInfo) {
super.init()
Task {
let viewModel = try await item.videoPlayerViewModel(with: mediaSource)
await MainActor.run {
self.currentViewModel = viewModel
}
}
}
}
// TODO: move to own file
class DownloadVideoPlayerManager: VideoPlayerManager {
init(downloadTask: DownloadTask) {
super.init()
guard let playbackURL = downloadTask.getMediaURL() else {
logger.error("Download task does not have media url for item: \(downloadTask.item.displayTitle)")
return
}
self.currentViewModel = .init(
playbackURL: playbackURL,
item: downloadTask.item,
mediaSource: .init(),
playSessionID: "",
videoStreams: downloadTask.item.videoStreams,
audioStreams: downloadTask.item.audioStreams,
subtitleStreams: downloadTask.item.subtitleStreams,
selectedAudioStreamIndex: 1,
selectedSubtitleStreamIndex: 1,
chapters: downloadTask.item.fullChapterInfo,
streamType: .direct
)
}
override func getAdjacentEpisodes(for item: BaseItemDto) {}
override func sendStartReport() {}
override func sendPauseReport() {}
override func sendStopReport() {}
override func sendProgressReport() {}
}

View File

@ -152,6 +152,10 @@
6334175B287DDFB9000603CE /* QuickConnectSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6334175A287DDFB9000603CE /* QuickConnectSettingsView.swift */; };
6334175D287DE0D0000603CE /* QuickConnectSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6334175C287DE0D0000603CE /* QuickConnectSettingsViewModel.swift */; };
AE8C3159265D6F90008AA076 /* bitrates.json in Resources */ = {isa = PBXBuildFile; fileRef = AE8C3158265D6F90008AA076 /* bitrates.json */; };
BD0BA22B2AD6503B00306A8D /* OnlineVideoPlayerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD0BA22A2AD6503B00306A8D /* OnlineVideoPlayerManager.swift */; };
BD0BA22C2AD6503B00306A8D /* OnlineVideoPlayerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD0BA22A2AD6503B00306A8D /* OnlineVideoPlayerManager.swift */; };
BD0BA22E2AD6508C00306A8D /* DownloadVideoPlayerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD0BA22D2AD6508C00306A8D /* DownloadVideoPlayerManager.swift */; };
BD0BA22F2AD6508C00306A8D /* DownloadVideoPlayerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD0BA22D2AD6508C00306A8D /* DownloadVideoPlayerManager.swift */; };
C400DB6A27FE894F007B65FE /* LiveTVChannelsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C400DB6927FE894F007B65FE /* LiveTVChannelsView.swift */; };
C400DB6B27FE8C97007B65FE /* LiveTVChannelItemElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4E52304272CE68800654268 /* LiveTVChannelItemElement.swift */; };
C400DB6D27FE8E65007B65FE /* LiveTVChannelItemWideElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = C400DB6C27FE8E65007B65FE /* LiveTVChannelItemWideElement.swift */; };
@ -903,6 +907,8 @@
6334175C287DE0D0000603CE /* QuickConnectSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickConnectSettingsViewModel.swift; sourceTree = "<group>"; };
637FCAF3287B5B2600C0A353 /* UDPBroadcast.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = UDPBroadcast.xcframework; path = Carthage/Build/UDPBroadcast.xcframework; sourceTree = "<group>"; };
AE8C3158265D6F90008AA076 /* bitrates.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = bitrates.json; sourceTree = "<group>"; };
BD0BA22A2AD6503B00306A8D /* OnlineVideoPlayerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnlineVideoPlayerManager.swift; sourceTree = "<group>"; };
BD0BA22D2AD6508C00306A8D /* DownloadVideoPlayerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadVideoPlayerManager.swift; sourceTree = "<group>"; };
C400DB6927FE894F007B65FE /* LiveTVChannelsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveTVChannelsView.swift; sourceTree = "<group>"; };
C400DB6C27FE8E65007B65FE /* LiveTVChannelItemWideElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveTVChannelItemWideElement.swift; sourceTree = "<group>"; };
C40CD924271F8D1E000FB198 /* ItemTypeLibraryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemTypeLibraryViewModel.swift; sourceTree = "<group>"; };
@ -1415,6 +1421,7 @@
532175392671BCED005491E6 /* ViewModels */ = {
isa = PBXGroup;
children = (
BD0BA2292AD6501300306A8D /* VideoPlayerManager */,
625CB5762678C34300530A6E /* ConnectToServerViewModel.swift */,
E17AC96E2954EE4B003D2BC2 /* DownloadListViewModel.swift */,
E113133928BEB71D00930F75 /* FilterViewModel.swift */,
@ -1438,7 +1445,6 @@
E1D3043128D175CE00587289 /* StaticLibraryViewModel.swift */,
E13DD3F82717E961009D4DAF /* UserListViewModel.swift */,
E13DD3EB27178A54009D4DAF /* UserSignInViewModel.swift */,
E1EA9F6928F8A79E00BEC442 /* VideoPlayerManager.swift */,
E14A08CA28E6831D004FC984 /* VideoPlayerViewModel.swift */,
625CB57B2678CE1000530A6E /* ViewModel.swift */,
);
@ -1935,6 +1941,16 @@
path = Resources;
sourceTree = "<group>";
};
BD0BA2292AD6501300306A8D /* VideoPlayerManager */ = {
isa = PBXGroup;
children = (
E1EA9F6928F8A79E00BEC442 /* VideoPlayerManager.swift */,
BD0BA22A2AD6503B00306A8D /* OnlineVideoPlayerManager.swift */,
BD0BA22D2AD6508C00306A8D /* DownloadVideoPlayerManager.swift */,
);
path = VideoPlayerManager;
sourceTree = "<group>";
};
E107BB9127880A4000354E07 /* ItemViewModel */ = {
isa = PBXGroup;
children = (
@ -3116,6 +3132,7 @@
E111D8FA28D0400900400001 /* PagingLibraryView.swift in Sources */,
E1D3043328D175CE00587289 /* StaticLibraryViewModel.swift in Sources */,
E1EA9F6B28F8A79E00BEC442 /* VideoPlayerManager.swift in Sources */,
BD0BA22F2AD6508C00306A8D /* DownloadVideoPlayerManager.swift in Sources */,
E1FCD08926C35A0D007C8DCF /* NetworkError.swift in Sources */,
E1549661296CA2EF00C4EF88 /* SwiftfinDefaults.swift in Sources */,
E158C8D12A31947500C527C5 /* MediaSourceInfoView.swift in Sources */,
@ -3202,6 +3219,7 @@
E1AD104E26D96CE3003E4A08 /* BaseItemDto.swift in Sources */,
E118959E289312020042947B /* BaseItemPerson+Poster.swift in Sources */,
62E632DD267D2E130063E547 /* SearchViewModel.swift in Sources */,
BD0BA22C2AD6503B00306A8D /* OnlineVideoPlayerManager.swift in Sources */,
E1575EA2293E7B1E001665B1 /* Color.swift in Sources */,
E1575E77293E77B5001665B1 /* MenuPosterHStackModel.swift in Sources */,
E12E30F5296392EC0022FAC9 /* EnumPickerView.swift in Sources */,
@ -3474,6 +3492,7 @@
E14A08CB28E6831D004FC984 /* VideoPlayerViewModel.swift in Sources */,
E1DC9847296DEFF500982F06 /* FavoriteIndicator.swift in Sources */,
E1E306CD28EF6E8000537998 /* TimerProxy.swift in Sources */,
BD0BA22E2AD6508C00306A8D /* DownloadVideoPlayerManager.swift in Sources */,
E18CE0B228A229E70092E7F1 /* UserDto.swift in Sources */,
E18E01F0288747230022598C /* AttributeHStack.swift in Sources */,
6334175B287DDFB9000603CE /* QuickConnectSettingsView.swift in Sources */,
@ -3578,6 +3597,7 @@
E1A2C154279A7D5A005EC829 /* UIApplication.swift in Sources */,
E1D8428F2933F2D900D1041A /* MediaSourceInfo.swift in Sources */,
E1BDF2EC2952290200CC0294 /* AspectFillActionButton.swift in Sources */,
BD0BA22B2AD6503B00306A8D /* OnlineVideoPlayerManager.swift in Sources */,
E1BDF2F529524E6400CC0294 /* PlayNextItemActionButton.swift in Sources */,
E18E01DD288747230022598C /* iPadOSSeriesItemContentView.swift in Sources */,
E18ACA952A15A3E100BB4F35 /* (null) in Sources */,