yeah ofc
Some checks are pending
Build and Release / Build IPA (push) Waiting to run
Build and Release / Build Mac Catalyst (push) Waiting to run

This commit is contained in:
cranci1 2025-06-16 11:49:16 +02:00
parent 3ac882de8c
commit 53fa2950e6

View file

@ -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() {
@ -106,14 +113,37 @@ class VideoPlayerViewController: UIViewController {
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)
.sink { [weak self] state in .sink { [weak self] state in
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()
} }
} }