From cd021df54de2f4b4785ac4afd8d9d2a5458da4fd Mon Sep 17 00:00:00 2001 From: Aravind Raveendran Date: Wed, 27 Sep 2023 11:44:51 +1000 Subject: [PATCH 1/2] Use different renderers on portrait and landscape mode to eliminate stopVideo on a renderer thats actively being used. --- .../Private/Models/StreamSourceAndViewRenderers.swift | 11 +++++++---- .../Private/Views/GridView/GridView.swift | 4 ++-- .../Private/Views/ListView/ListView.swift | 6 +++--- .../Private/Views/SingleStream/SingleStreamView.swift | 9 ++++++++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Sources/DolbyIORTSUIKit/Private/Models/StreamSourceAndViewRenderers.swift b/Sources/DolbyIORTSUIKit/Private/Models/StreamSourceAndViewRenderers.swift index dba16c4..8080d61 100644 --- a/Sources/DolbyIORTSUIKit/Private/Models/StreamSourceAndViewRenderers.swift +++ b/Sources/DolbyIORTSUIKit/Private/Models/StreamSourceAndViewRenderers.swift @@ -6,14 +6,17 @@ import DolbyIORTSCore import Foundation final class ViewRendererProvider: ObservableObject { - private var rendererDictionary: [UUID: StreamSourceViewRenderer] = [:] + + private var rendererDictionary: [String: StreamSourceViewRenderer] = [:] - func renderer(for source: StreamSource) -> StreamSourceViewRenderer { - if let renderer = rendererDictionary[source.id] { + func renderer(for source: StreamSource, isPortait: Bool) -> StreamSourceViewRenderer { + let orientationKey = isPortait ? "Portrait" : "Landscape" + let storageKey = "\(source.id)_\(orientationKey)" + if let renderer = rendererDictionary[storageKey] { return renderer } else { let renderer = StreamSourceViewRenderer(source) - rendererDictionary[source.id] = renderer + rendererDictionary[storageKey] = renderer return renderer } } diff --git a/Sources/DolbyIORTSUIKit/Private/Views/GridView/GridView.swift b/Sources/DolbyIORTSUIKit/Private/Views/GridView/GridView.swift index 38aa860..a13c1ef 100644 --- a/Sources/DolbyIORTSUIKit/Private/Views/GridView/GridView.swift +++ b/Sources/DolbyIORTSUIKit/Private/Views/GridView/GridView.swift @@ -73,7 +73,7 @@ struct GridView: View { VideoRendererView( viewModel: viewModel, - viewRenderer: viewRendererProvider.renderer(for: viewModel.streamSource), + viewRenderer: viewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait), maxWidth: maxAllowedSubVideoWidth, maxHeight: maxAllowedSubVideoHeight, contentMode: .aspectFit @@ -96,7 +96,7 @@ struct GridView: View { ForEach(viewModel.allVideoViewModels, id: \.streamSource.id) { viewModel in VideoRendererView( viewModel: viewModel, - viewRenderer: viewRendererProvider.renderer(for: viewModel.streamSource), + viewRenderer: viewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait), maxWidth: .infinity, maxHeight: availableHeight / CGFloat(rowsCount), contentMode: .aspectFit diff --git a/Sources/DolbyIORTSUIKit/Private/Views/ListView/ListView.swift b/Sources/DolbyIORTSUIKit/Private/Views/ListView/ListView.swift index 3d2de7a..bea68ff 100644 --- a/Sources/DolbyIORTSUIKit/Private/Views/ListView/ListView.swift +++ b/Sources/DolbyIORTSUIKit/Private/Views/ListView/ListView.swift @@ -210,7 +210,7 @@ struct ListView: View { let viewModel = viewModel.primaryVideoViewModel return VideoRendererView( viewModel: viewModel, - viewRenderer: mainViewRendererProvider.renderer(for: viewModel.streamSource), + viewRenderer: mainViewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait), maxWidth: maxAllowedMainVideoSize.width, maxHeight: maxAllowedMainVideoSize.height, contentMode: .aspectFit @@ -227,7 +227,7 @@ struct ListView: View { VideoRendererView( viewModel: viewModel, - viewRenderer: thumbnailViewRendererProvider.renderer(for: viewModel.streamSource), + viewRenderer: thumbnailViewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait), maxWidth: maxAllowedSubVideoWidth, maxHeight: maxAllowedSubVideoHeight, contentMode: .aspectFit @@ -257,7 +257,7 @@ struct ListView: View { ForEach(viewModel.secondaryVideoViewModels, id: \.streamSource.id) { viewModel in VideoRendererView( viewModel: viewModel, - viewRenderer: thumbnailViewRendererProvider.renderer(for: viewModel.streamSource), + viewRenderer: thumbnailViewRendererProvider.renderer(for: viewModel.streamSource, isPortait: deviceOrientation.isPortrait), maxWidth: .infinity, maxHeight: availableHeight, contentMode: .aspectFit diff --git a/Sources/DolbyIORTSUIKit/Private/Views/SingleStream/SingleStreamView.swift b/Sources/DolbyIORTSUIKit/Private/Views/SingleStream/SingleStreamView.swift index 5d06ef2..55c3af0 100644 --- a/Sources/DolbyIORTSUIKit/Private/Views/SingleStream/SingleStreamView.swift +++ b/Sources/DolbyIORTSUIKit/Private/Views/SingleStream/SingleStreamView.swift @@ -23,6 +23,8 @@ struct SingleStreamView: View { @State private var selectedVideoStreamSourceId: UUID @State private var isShowingSettingsScreen: Bool = false @State private var isShowingStatsInfoScreen: Bool = false + @State private var deviceOrientation: UIDeviceOrientation = UIDeviceOrientation.portrait + @StateObject private var userInteractionViewModel: UserInteractionViewModel = .init() @StateObject private var viewRendererProvider: ViewRendererProvider = .init() @@ -100,7 +102,7 @@ struct SingleStreamView: View { let maxAllowedVideoHeight = proxy.size.height VideoRendererView( viewModel: videoRendererViewModel, - viewRenderer: viewRendererProvider.renderer(for: videoRendererViewModel.streamSource), + viewRenderer: viewRendererProvider.renderer(for: videoRendererViewModel.streamSource, isPortait: deviceOrientation.isPortrait), maxWidth: maxAllowedVideoWidth, maxHeight: maxAllowedVideoHeight, contentMode: .aspectFit @@ -149,6 +151,11 @@ struct SingleStreamView: View { } .navigationBarHidden(isShowingDetailPresentation) } + .onRotate { newOrientation in + if !newOrientation.isFlat && newOrientation.isValidInterfaceOrientation { + deviceOrientation = newOrientation + } + } } private func statisticsView() -> some View { From 1c2827be7f58d684063e9eaa3f318a0a716af162 Mon Sep 17 00:00:00 2001 From: Aravind Raveendran Date: Wed, 27 Sep 2023 12:02:19 +1000 Subject: [PATCH 2/2] Disable idle timer when the video is played back --- .../Public/Screens/Media/StreamingScreen.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/DolbyIORTSUIKit/Public/Screens/Media/StreamingScreen.swift b/Sources/DolbyIORTSUIKit/Public/Screens/Media/StreamingScreen.swift index 2075955..844ae3e 100644 --- a/Sources/DolbyIORTSUIKit/Public/Screens/Media/StreamingScreen.swift +++ b/Sources/DolbyIORTSUIKit/Public/Screens/Media/StreamingScreen.swift @@ -175,6 +175,12 @@ public struct StreamingScreen: View { .navigationBarTitleDisplayMode(.inline) .navigationBarBackButtonHidden(true) } + .onAppear { + UIApplication.shared.isIdleTimerDisabled = true + } + .onDisappear { + UIApplication.shared.isIdleTimerDisabled = false + } } }