mirror of
https://github.com/cranci1/Sora.git
synced 2026-05-10 03:50:47 +00:00
Merge branch 'dev'
This commit is contained in:
commit
0fdbd3e452
1 changed files with 45 additions and 7 deletions
|
|
@ -31,6 +31,7 @@ class VideoPlayerViewController: UIViewController {
|
||||||
|
|
||||||
private var groupSession: GroupSession<VideoWatchingActivity>?
|
private var groupSession: GroupSession<VideoWatchingActivity>?
|
||||||
private var subscriptions = Set<AnyCancellable>()
|
private var subscriptions = Set<AnyCancellable>()
|
||||||
|
private var isLaunchedFromSharePlay = false
|
||||||
|
|
||||||
private var aniListUpdateSent = false
|
private var aniListUpdateSent = false
|
||||||
private var aniListUpdatedSuccessfully = false
|
private var aniListUpdatedSuccessfully = false
|
||||||
|
|
@ -48,7 +49,15 @@ class VideoPlayerViewController: UIViewController {
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
configureGroupSession()
|
||||||
|
if isLaunchedFromSharePlay {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setupVideoPlayer()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupVideoPlayer() {
|
||||||
guard let streamUrl = streamUrl, let url = URL(string: streamUrl) else {
|
guard let streamUrl = streamUrl, let url = URL(string: streamUrl) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -90,8 +99,6 @@ class VideoPlayerViewController: UIViewController {
|
||||||
} else {
|
} else {
|
||||||
self.player?.play()
|
self.player?.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
configureGroupSession()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func configureGroupSession() {
|
private func configureGroupSession() {
|
||||||
|
|
@ -105,6 +112,27 @@ class VideoPlayerViewController: UIViewController {
|
||||||
@MainActor
|
@MainActor
|
||||||
private func configureGroupSession(_ groupSession: GroupSession<VideoWatchingActivity>) async {
|
private func configureGroupSession(_ groupSession: GroupSession<VideoWatchingActivity>) async {
|
||||||
self.groupSession = groupSession
|
self.groupSession = groupSession
|
||||||
|
|
||||||
|
let activity = groupSession.activity
|
||||||
|
|
||||||
|
if streamUrl == nil {
|
||||||
|
streamUrl = activity.streamUrl
|
||||||
|
fullUrl = activity.fullUrl
|
||||||
|
subtitles = activity.subtitles
|
||||||
|
aniListID = activity.aniListID
|
||||||
|
headers = activity.headers
|
||||||
|
totalEpisodes = activity.totalEpisodes
|
||||||
|
tmdbID = activity.tmdbID
|
||||||
|
isMovie = activity.isMovie
|
||||||
|
seasonNumber = activity.seasonNumber
|
||||||
|
episodeNumber = activity.episodeNumber
|
||||||
|
episodeImageUrl = activity.episodeImageUrl
|
||||||
|
mediaTitle = activity.mediaTitle
|
||||||
|
|
||||||
|
isLaunchedFromSharePlay = true
|
||||||
|
|
||||||
|
setupVideoPlayer()
|
||||||
|
}
|
||||||
|
|
||||||
groupSession.$state
|
groupSession.$state
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
|
@ -112,8 +140,10 @@ class VideoPlayerViewController: UIViewController {
|
||||||
switch state {
|
switch state {
|
||||||
case .joined:
|
case .joined:
|
||||||
self?.coordinatePlayback()
|
self?.coordinatePlayback()
|
||||||
|
Logger.shared.log("Joined SharePlay session", type: "SharePlay")
|
||||||
case .invalidated:
|
case .invalidated:
|
||||||
self?.groupSession = nil
|
self?.groupSession = nil
|
||||||
|
Logger.shared.log("SharePlay session invalidated", type: "SharePlay")
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -121,6 +151,7 @@ class VideoPlayerViewController: UIViewController {
|
||||||
.store(in: &subscriptions)
|
.store(in: &subscriptions)
|
||||||
|
|
||||||
groupSession.join()
|
groupSession.join()
|
||||||
|
Logger.shared.log("Automatically joining SharePlay session for: \(activity.mediaTitle)", type: "SharePlay")
|
||||||
}
|
}
|
||||||
|
|
||||||
private func coordinatePlayback() {
|
private func coordinatePlayback() {
|
||||||
|
|
@ -176,11 +207,18 @@ class VideoPlayerViewController: UIViewController {
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
player?.play()
|
|
||||||
setInitialPlayerRate()
|
|
||||||
|
|
||||||
Task {
|
// Only start normal playback if not launched from SharePlay
|
||||||
await checkForFaceTimeAndPromptSharePlay()
|
if !isLaunchedFromSharePlay {
|
||||||
|
player?.play()
|
||||||
|
setInitialPlayerRate()
|
||||||
|
|
||||||
|
Task {
|
||||||
|
await checkForFaceTimeAndPromptSharePlay()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For SharePlay launches, the playback will be coordinated
|
||||||
|
setInitialPlayerRate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue