mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-18 15:12:09 +00:00
fixed media player
This commit is contained in:
parent
cb6ce4c720
commit
c002671281
5 changed files with 45 additions and 40 deletions
|
|
@ -16,5 +16,6 @@ struct ContinueWatchingItem: Codable, Identifiable {
|
|||
let streamUrl: String
|
||||
let fullUrl: String
|
||||
let subtitles: String?
|
||||
let aniListID: Int?
|
||||
let module: ScrapingModule
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class CustomMediaPlayerViewController: UIViewController {
|
|||
let episodeImageUrl: String
|
||||
let subtitlesURL: String?
|
||||
let onWatchNext: () -> Void
|
||||
let aniListID: Int
|
||||
|
||||
var player: AVPlayer!
|
||||
var timeObserverToken: Any?
|
||||
|
|
@ -56,7 +57,6 @@ class CustomMediaPlayerViewController: UIViewController {
|
|||
var lastDuration: Double = 0.0
|
||||
var watchNextButtonAppearedAt: Double?
|
||||
|
||||
// MARK: - Constraint Sets
|
||||
var portraitButtonVisibleConstraints: [NSLayoutConstraint] = []
|
||||
var portraitButtonHiddenConstraints: [NSLayoutConstraint] = []
|
||||
var landscapeButtonVisibleConstraints: [NSLayoutConstraint] = []
|
||||
|
|
@ -120,6 +120,7 @@ class CustomMediaPlayerViewController: UIViewController {
|
|||
episodeNumber: Int,
|
||||
onWatchNext: @escaping () -> Void,
|
||||
subtitlesURL: String?,
|
||||
aniListID: Int,
|
||||
episodeImageUrl: String) {
|
||||
|
||||
self.module = module
|
||||
|
|
@ -130,6 +131,7 @@ class CustomMediaPlayerViewController: UIViewController {
|
|||
self.episodeImageUrl = episodeImageUrl
|
||||
self.onWatchNext = onWatchNext
|
||||
self.subtitlesURL = subtitlesURL
|
||||
self.aniListID = aniListID
|
||||
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
||||
|
|
@ -268,28 +270,9 @@ class CustomMediaPlayerViewController: UIViewController {
|
|||
UserDefaults.standard.set(playbackSpeed, forKey: "lastPlaybackSpeed")
|
||||
}
|
||||
|
||||
if let currentItem = player.currentItem, currentItem.duration.seconds > 0 {
|
||||
let progress = currentTimeVal / currentItem.duration.seconds
|
||||
let item = ContinueWatchingItem(
|
||||
id: UUID(),
|
||||
imageUrl: episodeImageUrl,
|
||||
episodeNumber: episodeNumber,
|
||||
mediaTitle: titleText,
|
||||
progress: progress,
|
||||
streamUrl: streamURL,
|
||||
fullUrl: fullUrl,
|
||||
subtitles: subtitlesURL,
|
||||
module: module
|
||||
)
|
||||
ContinueWatchingManager.shared.save(item: item)
|
||||
}
|
||||
}
|
||||
|
||||
override func observeValue(forKeyPath keyPath: String?,
|
||||
of object: Any?,
|
||||
change: [NSKeyValueChangeKey : Any]?,
|
||||
context: UnsafeMutableRawPointer?) {
|
||||
|
||||
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
||||
guard context == &playerItemKVOContext else {
|
||||
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
|
||||
return
|
||||
|
|
@ -1011,6 +994,23 @@ class CustomMediaPlayerViewController: UIViewController {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
if let currentItem = player.currentItem, currentItem.duration.seconds > 0 {
|
||||
let progress = currentTimeVal / currentItem.duration.seconds
|
||||
let item = ContinueWatchingItem(
|
||||
id: UUID(),
|
||||
imageUrl: episodeImageUrl,
|
||||
episodeNumber: episodeNumber,
|
||||
mediaTitle: titleText,
|
||||
progress: progress,
|
||||
streamUrl: streamURL,
|
||||
fullUrl: fullUrl,
|
||||
subtitles: subtitlesURL,
|
||||
aniListID: aniListID,
|
||||
module: module
|
||||
)
|
||||
ContinueWatchingManager.shared.save(item: item)
|
||||
}
|
||||
}
|
||||
|
||||
func repositionWatchNextButton() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class VideoPlayerViewController: UIViewController {
|
|||
var streamUrl: String?
|
||||
var fullUrl: String = ""
|
||||
var subtitles: String = ""
|
||||
var aniListID: Int = 0
|
||||
|
||||
var episodeNumber: Int = 0
|
||||
var episodeImageUrl: String = ""
|
||||
|
|
@ -87,25 +88,6 @@ class VideoPlayerViewController: UIViewController {
|
|||
player?.removeTimeObserver(timeObserverToken)
|
||||
self.timeObserverToken = nil
|
||||
}
|
||||
|
||||
if let currentItem = player?.currentItem, currentItem.duration.seconds > 0,
|
||||
let streamUrl = streamUrl {
|
||||
let currentTime = UserDefaults.standard.double(forKey: "lastPlayedTime_\(fullUrl)")
|
||||
let duration = currentItem.duration.seconds
|
||||
let progress = currentTime / duration
|
||||
let item = ContinueWatchingItem(
|
||||
id: UUID(),
|
||||
imageUrl: episodeImageUrl,
|
||||
episodeNumber: episodeNumber,
|
||||
mediaTitle: mediaTitle,
|
||||
progress: progress,
|
||||
streamUrl: streamUrl,
|
||||
fullUrl: fullUrl,
|
||||
subtitles: subtitles,
|
||||
module: module
|
||||
)
|
||||
ContinueWatchingManager.shared.save(item: item)
|
||||
}
|
||||
}
|
||||
|
||||
private func setInitialPlayerRate() {
|
||||
|
|
@ -131,6 +113,26 @@ class VideoPlayerViewController: UIViewController {
|
|||
UserDefaults.standard.set(currentTime, forKey: "lastPlayedTime_\(fullURL)")
|
||||
UserDefaults.standard.set(duration, forKey: "totalTime_\(fullURL)")
|
||||
}
|
||||
|
||||
if let currentItem = player.currentItem, currentItem.duration.seconds > 0,
|
||||
let streamUrl = streamUrl {
|
||||
let currentTime = UserDefaults.standard.double(forKey: "lastPlayedTime_\(fullUrl)")
|
||||
let duration = currentItem.duration.seconds
|
||||
let progress = currentTime / duration
|
||||
let item = ContinueWatchingItem(
|
||||
id: UUID(),
|
||||
imageUrl: episodeImageUrl,
|
||||
episodeNumber: episodeNumber,
|
||||
mediaTitle: mediaTitle,
|
||||
progress: progress,
|
||||
streamUrl: streamUrl,
|
||||
fullUrl: fullUrl,
|
||||
subtitles: subtitles,
|
||||
aniListID: aniListID,
|
||||
module: module
|
||||
)
|
||||
ContinueWatchingManager.shared.save(item: item)
|
||||
}
|
||||
}
|
||||
|
||||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
||||
|
|
|
|||
|
|
@ -248,6 +248,7 @@ struct ContinueWatchingCell: View {
|
|||
episodeNumber: item.episodeNumber,
|
||||
onWatchNext: { },
|
||||
subtitlesURL: item.subtitles,
|
||||
aniListID: item.aniListID ?? 0,
|
||||
episodeImageUrl: item.imageUrl
|
||||
)
|
||||
customMediaPlayer.modalPresentationStyle = .fullScreen
|
||||
|
|
|
|||
|
|
@ -725,6 +725,7 @@ struct MediaInfoView: View {
|
|||
selectNextEpisode()
|
||||
},
|
||||
subtitlesURL: subtitles,
|
||||
aniListID: itemID ?? 0,
|
||||
episodeImageUrl: selectedEpisodeImage
|
||||
)
|
||||
customMediaPlayer.modalPresentationStyle = .fullScreen
|
||||
|
|
|
|||
Loading…
Reference in a new issue