continue watching button working i think

This commit is contained in:
cranci1 2025-02-03 17:17:25 +01:00
parent a0588fedfa
commit a69f65242f
4 changed files with 41 additions and 10 deletions

View file

@ -21,7 +21,7 @@ struct CustomVideoPlayer: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {
// yes? Like the plural of the famous american rapper ye? -IBHRAD
// low taper fade the meme is massive
// low taper fade the meme is massive -cranci
}
}
@ -156,7 +156,7 @@ struct CustomMediaPlayer: View {
.padding(.horizontal, 32)
}
Spacer()
if duration - currentTime <= duration * 0.10 && currentTime != duration && showWatchNextButton {
if duration - currentTime <= duration * 0.10 && currentTime != duration && showWatchNextButton && duration != 0 {
Button(action: {
player.pause()
presentationMode.wrappedValue.dismiss()

View file

@ -24,7 +24,7 @@ struct CircularProgressBar: View {
.rotationEffect(Angle(degrees: 270.0))
.animation(.linear, value: progress)
if progress >= 0.90 {
if progress >= 0.9 {
Image(systemName: "checkmark")
.font(.system(size: 12))
} else {

View file

@ -26,8 +26,8 @@ struct EpisodeCell: View {
@State private var currentProgress: Double = 0.0
private func markAsWatched() {
UserDefaults.standard.set(9999999.0, forKey: "lastPlayedTime_\(episode)")
UserDefaults.standard.set(9999999.0, forKey: "totalTime_\(episode)")
UserDefaults.standard.set(99999999.0, forKey: "lastPlayedTime_\(episode)")
UserDefaults.standard.set(99999999.0, forKey: "totalTime_\(episode)")
updateProgress()
}

View file

@ -107,7 +107,7 @@ struct MediaInfoView: View {
.frame(width: 20, height: 20)
.foregroundColor(.primary)
}
.padding(5)
.padding(4)
.background(Capsule().fill(Color.accentColor.opacity(0.4)))
}
}
@ -139,11 +139,12 @@ struct MediaInfoView: View {
HStack {
Button(action: {
playFirstUnwatchedEpisode()
}) {
HStack {
Image(systemName: "play.fill")
.foregroundColor(.primary)
Text("Start Watching")
Text(startWatchingText)
.font(.headline)
.foregroundColor(.primary)
}
@ -205,7 +206,6 @@ struct MediaInfoView: View {
if !isFetchingEpisode {
isFetchingEpisode = true
fetchStream(href: ep.href)
DropManager.shared.showDrop(title: "Fetching Stream", subtitle: "", duration: 0.5, icon: UIImage(systemName: "arrow.triangle.2.circlepath"))
}
}
.disabled(isFetchingEpisode)
@ -267,6 +267,35 @@ struct MediaInfoView: View {
}
}
private var startWatchingText: String {
for ep in episodeLinks {
let lastPlayedTime = UserDefaults.standard.double(forKey: "lastPlayedTime_\(ep.href)")
let totalTime = UserDefaults.standard.double(forKey: "totalTime_\(ep.href)")
let progress = totalTime > 0 ? lastPlayedTime / totalTime : 0
if progress >= 0.1 && (totalTime - lastPlayedTime) > (totalTime * 0.1) {
return "Continue Watching Episode \(ep.number)"
}
}
return "Start Watching"
}
private func playFirstUnwatchedEpisode() {
for ep in episodeLinks {
let lastPlayedTime = UserDefaults.standard.double(forKey: "lastPlayedTime_\(ep.href)")
let totalTime = UserDefaults.standard.double(forKey: "totalTime_\(ep.href)")
let progress = totalTime > 0 ? lastPlayedTime / totalTime : 0
if progress >= 0.1 && (totalTime - lastPlayedTime) > (totalTime * 0.1) {
selectedEpisodeNumber = ep.number
fetchStream(href: ep.href)
return
}
}
if let firstEpisode = episodeLinks.first {
selectedEpisodeNumber = firstEpisode.number
fetchStream(href: firstEpisode.href)
}
}
private func generateRanges() -> [Range<Int>] {
let chunkSize = episodeChunkSize
let totalEpisodes = episodeLinks.count
@ -297,8 +326,7 @@ struct MediaInfoView: View {
self.isLoading = false
self.isRefetching = false
}
}
else {
} else {
jsController.fetchDetails(url: href) { items, episodes in
if let item = items.first {
self.synopsis = item.description
@ -320,6 +348,7 @@ struct MediaInfoView: View {
}
func fetchStream(href: String) {
DropManager.shared.showDrop(title: "Fetching Stream", subtitle: "", duration: 0.5, icon: UIImage(systemName: "arrow.triangle.2.circlepath"))
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Task {
do {
@ -397,6 +426,8 @@ struct MediaInfoView: View {
selectNextEpisode()
}
)
print(Int(selectedEpisodeNumber))
print(selectedEpisodeNumber)
let hostingController = UIHostingController(rootView: customMediaPlayer)
hostingController.modalPresentationStyle = .fullScreen
Logger.shared.log("Opening custom media player with url: \(url)")