diff --git a/ios/brave-ios/Sources/PlaylistUI/PlayerModel.swift b/ios/brave-ios/Sources/PlaylistUI/PlayerModel.swift index aec90722e2aa..f269810f2b4b 100644 --- a/ios/brave-ios/Sources/PlaylistUI/PlayerModel.swift +++ b/ios/brave-ios/Sources/PlaylistUI/PlayerModel.swift @@ -332,43 +332,6 @@ public final class PlayerModel: ObservableObject { return item.presentationSize.width / item.presentationSize.height } - /// A stream that yields downsampled thumbnails of the item currently playing. - var videoAmbianceImageStream: AsyncStream { - return .init { [weak self] continuation in - guard let self else { return } - let timeObserver = player.addCancellablePeriodicTimeObserver( - forInterval: 150, - queue: .global() - ) { [weak self] time in - guard let self, - self.videoDecorationOutput.hasNewPixelBuffer(forItemTime: time), - let buffer = self.videoDecorationOutput.copyPixelBuffer( - forItemTime: time, - itemTimeForDisplay: nil - ) - else { - DispatchQueue.main.async { - continuation.yield(.init()) - } - return - } - let ciImage = CIImage(cvPixelBuffer: buffer) - .transformed(by: .init(scaleX: 0.1, y: 0.1), highQualityDownsample: false) - if let cgImage = CIContext().createCGImage(ciImage, from: ciImage.extent) { - let uiImage = UIImage(cgImage: cgImage) - DispatchQueue.main.async { - continuation.yield(uiImage) - } - } - } - // Should be tied to the View, but adding one extra killswitch - self.cancellables.insert(timeObserver) - continuation.onTermination = { _ in - timeObserver.cancel() - } - } - } - @MainActor @Published public var isPlayerInForeground: Bool = true // MARK: - Picture in Picture @@ -709,15 +672,11 @@ public final class PlayerModel: ObservableObject { // MARK: - private let player: AVPlayer = .init() - private let videoDecorationOutput = AVPlayerItemVideoOutput(pixelBufferAttributes: [ - kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA - ]) private var currentItem: AVPlayerItem? { player.currentItem } nonisolated private func updateCurrentItem(_ item: AVPlayerItem?) async { player.replaceCurrentItem(with: item) - item?.add(videoDecorationOutput) await MainActor.run { setupPlayerItemKeyPathObservation() updateSystemPlayer() @@ -804,15 +763,7 @@ public final class PlayerModel: ObservableObject { if isPictureInPictureActive || playerLayer.player != nil { return } - // There is a bug in iOS that breaks restoring an AVPlayer to an AVPlayerLayer while its - // playing in the background, so we have to first pause it before restoring it and resume - // playback after. - let isPlayingDurationRestoration = isPlaying - pause() playerLayer.player = player - if isPlayingDurationRestoration { - play() - } } cancellables.formUnion([ diff --git a/ios/brave-ios/Sources/PlaylistUI/PlayerView.swift b/ios/brave-ios/Sources/PlaylistUI/PlayerView.swift index cbc5bec6760d..2ab977cfabca 100644 --- a/ios/brave-ios/Sources/PlaylistUI/PlayerView.swift +++ b/ios/brave-ios/Sources/PlaylistUI/PlayerView.swift @@ -38,23 +38,10 @@ struct PlayerView: View { } } - private var isVideoAmbianceBackgroundEnabled: Bool { - !isFullScreen && playerModel.isPlayerInForeground - && !ProcessInfo.processInfo.isLowPowerModeEnabled - } - var body: some View { VideoPlayerLayout(aspectRatio: isFullScreen ? nil : 16 / 9) { VideoPlayer(playerLayer: playerModel.playerLayer) } - .background { - if isVideoAmbianceBackgroundEnabled { - VideoAmbianceBackground(playerModel: playerModel) - .transition(.opacity.animation(.snappy)) - .opacity(playerModel.isPlaying ? 1 : 0.5) - .animation(.default, value: playerModel.isPlaying) - } - } .allowsHitTesting(false) // For some reason this is required or the status bar breaks when touching anything on the // screen on an iPad... @@ -312,31 +299,6 @@ extension PlayerView { } } -struct VideoAmbianceBackground: View { - var playerModel: PlayerModel - - @State private var videoAmbianceDecorationImage: UIImage? - - var body: some View { - VStack { - if let videoAmbianceDecorationImage { - Image(uiImage: videoAmbianceDecorationImage) - .resizable() - .blur(radius: 30) - .id(videoAmbianceDecorationImage) - .transition(.opacity) - } - } - .task(priority: .medium) { - for await image in playerModel.videoAmbianceImageStream { - withAnimation { - videoAmbianceDecorationImage = image.size == .zero ? nil : image - } - } - } - } -} - struct CompactMediaScrubberLabel: View { var currentTime: TimeInterval var duration: PlayerModel.ItemDuration