-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MultiChannels for tvOS player #217
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
rts-viewer-tvos/RTSViewer/ChannelDetailInputView/ChannelDetailInputBox.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// | ||
// ChannelDetailInputBox.swift | ||
// | ||
|
||
import DolbyIOUIKit | ||
import RTSCore | ||
import SwiftUI | ||
|
||
struct ChannelDetailInputBox: View { | ||
@ObservedObject var viewModel: ChannelDetailInputViewModel | ||
|
||
init(viewModel: ChannelDetailInputViewModel) { | ||
self.viewModel = viewModel | ||
} | ||
|
||
var body: some View { | ||
GeometryReader { proxy in | ||
VStack(spacing: Layout.spacing2x) { | ||
Text( | ||
text: "stream-detail-input.header.label", | ||
fontAsset: .avenirNextDemiBold( | ||
size: FontSize.body, | ||
style: .body | ||
) | ||
) | ||
|
||
VStack(spacing: Layout.spacing1x) { | ||
Text( | ||
text: "channel-detail-input.start-a-channel.label", | ||
mode: .secondary, | ||
fontAsset: .avenirNextDemiBold( | ||
size: FontSize.title3, | ||
style: .title3 | ||
) | ||
) | ||
|
||
Text( | ||
text: "channel-detail-input.subtitle.label", | ||
fontAsset: .avenirNextRegular( | ||
size: FontSize.caption2, | ||
style: .caption2 | ||
) | ||
) | ||
} | ||
ScrollView { | ||
channelInput(placeholderStream: "channel-detail-input.streamName.placeholder1.label", | ||
placeholderAccount: "channel-detail-input.accountId.placeholder1.label", | ||
channelName: "channel-detail-input.channel-1.label", | ||
streamName: $viewModel.streamName1, | ||
accountID: $viewModel.accountID1) | ||
|
||
channelInput(placeholderStream: "channel-detail-input.streamName.placeholder2.label", | ||
placeholderAccount: "channel-detail-input.accountId.placeholder2.label", | ||
channelName: "channel-detail-input.channel-2.label", | ||
streamName: $viewModel.streamName2, | ||
accountID: $viewModel.accountID2) | ||
|
||
channelInput(placeholderStream: "channel-detail-input.streamName.placeholder3.label", | ||
placeholderAccount: "channel-detail-input.accountId.placeholder3.label", | ||
channelName: "channel-detail-input.channel-3.label", | ||
streamName: $viewModel.streamName3, | ||
accountID: $viewModel.accountID3) | ||
|
||
channelInput(placeholderStream: "channel-detail-input.streamName.placeholder4.label", | ||
placeholderAccount: "channel-detail-input.accountId.placeholder4.label", | ||
channelName: "channel-detail-input.channel-4.label", | ||
streamName: $viewModel.streamName4, | ||
accountID: $viewModel.accountID4) | ||
} | ||
|
||
Button( | ||
action: { | ||
viewModel.playButtonPressed() | ||
}, | ||
text: "stream-detail-input.play.button" | ||
) | ||
|
||
Spacer() | ||
.frame(height: Layout.spacing8x) | ||
} | ||
.padding(.all, Layout.spacing5x) | ||
.background(Color(uiColor: UIColor.Background.black)) | ||
.cornerRadius(Layout.cornerRadius6x) | ||
.frame(width: proxy.size.width / 3) | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private func channelInput( | ||
placeholderStream: LocalizedStringKey, | ||
placeholderAccount: LocalizedStringKey, | ||
channelName: LocalizedStringKey, | ||
streamName: Binding<String>, | ||
accountID: Binding<String> | ||
) -> some View { | ||
VStack(alignment: .leading, spacing: Layout.spacing2x) { | ||
Text(text: channelName, | ||
font: .custom("AvenirNext-Bold", size: FontSize.caption1, relativeTo: .caption) | ||
) | ||
.multilineTextAlignment(.leading) | ||
.padding(.top, Layout.spacing3x) | ||
|
||
TextField(placeholderStream, text: streamName) | ||
.font(.avenirNextRegular(withStyle: .caption, size: FontSize.caption1)) | ||
|
||
TextField(placeholderAccount, text: accountID) | ||
.font(.avenirNextRegular(withStyle: .caption, size: FontSize.caption1)) | ||
|
||
} | ||
} | ||
} | ||
|
||
// #Preview { | ||
// ChannelDetailInputBox(viewModel: ChannelDetailInputViewModel(isShowingChannelView: .constant(true), onPlayTapped: {})) | ||
// } |
81 changes: 81 additions & 0 deletions
81
rts-viewer-tvos/RTSViewer/ChannelDetailInputView/ChannelDetailInputViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// ChannelDetailInputViewModel.swift | ||
// | ||
|
||
import Foundation | ||
import RTSCore | ||
import SwiftUI | ||
|
||
struct StreamPair { | ||
let streamName: String | ||
let accountID: String | ||
} | ||
|
||
@MainActor | ||
class ChannelDetailInputViewModel: ObservableObject { | ||
@Binding private var isShowingChannelView: Bool | ||
@Binding private var channels: [Channel]? | ||
|
||
@Published var streamName1: String = "game" | ||
@Published var accountID1: String = "7csQUs" | ||
@Published var streamName2: String = "multiview" | ||
@Published var accountID2: String = "k9Mwad" | ||
@Published var streamName3: String = "game" | ||
@Published var accountID3: String = "7csQUs" | ||
@Published var streamName4: String = "multiview" | ||
@Published var accountID4: String = "k9Mwad" | ||
|
||
init( | ||
channels: Binding<[Channel]?>, isShowingChannelView: Binding<Bool>) { | ||
self._channels = channels | ||
self._isShowingChannelView = isShowingChannelView | ||
} | ||
|
||
func playButtonPressed() { | ||
var confirmedChannels = [Channel]() | ||
let streamDetails = createStreamDetailArray() | ||
for detail in streamDetails { | ||
guard let channel = setupChannel(for: detail) else { return } | ||
confirmedChannels.append(channel) | ||
} | ||
guard !confirmedChannels.isEmpty else { return } | ||
channels = confirmedChannels | ||
isShowingChannelView = true | ||
} | ||
} | ||
|
||
private extension ChannelDetailInputViewModel { | ||
func setupChannel(for detail: StreamPair) -> Channel? { | ||
guard !detail.streamName.isEmpty, !detail.accountID.isEmpty else { return nil } | ||
let subscriptionManager = SubscriptionManager() | ||
let videoTracksManager = VideoTracksManager(subscriptionManager: subscriptionManager) | ||
return Channel(streamDetail: detail, | ||
subscriptionManager: subscriptionManager, | ||
videoTracksManager: videoTracksManager) | ||
} | ||
|
||
func createStreamDetailArray() -> [StreamPair] { | ||
var streamPairs = [StreamPair]() | ||
if !streamName1.isEmpty, !accountID1.isEmpty { | ||
let streamPair = StreamPair(streamName: streamName1, accountID: accountID1) | ||
streamPairs.append(streamPair) | ||
} | ||
if !streamName2.isEmpty, !accountID2.isEmpty { | ||
let streamPair = StreamPair(streamName: streamName2, accountID: accountID2) | ||
streamPairs.append(streamPair) | ||
} | ||
if !streamName3.isEmpty, !accountID3.isEmpty { | ||
let streamPair = StreamPair(streamName: streamName3, accountID: accountID3) | ||
streamPairs.append(streamPair) | ||
} | ||
if !streamName4.isEmpty, !accountID4.isEmpty { | ||
let streamPair = StreamPair(streamName: streamName4, accountID: accountID4) | ||
streamPairs.append(streamPair) | ||
} | ||
return streamPairs | ||
} | ||
|
||
func checkIfCredentialsAreValid(streamName: String, accountID: String) -> Bool { | ||
return streamName.count > 0 && accountID.count > 0 | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
rts-viewer-tvos/RTSViewer/ChannelGridView/ChannelGridView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// ChannelGridView.swift | ||
// | ||
|
||
import DolbyIOUIKit | ||
import MillicastSDK | ||
import RTSCore | ||
import SwiftUI | ||
|
||
struct ChannelGridView: View { | ||
private let viewModel: ChannelGridViewModel | ||
|
||
static let numberOfColumns = 2 | ||
|
||
init(viewModel: ChannelGridViewModel) { | ||
self.viewModel = viewModel | ||
} | ||
|
||
var body: some View { | ||
GeometryReader { proxy in | ||
let screenSize = proxy.size | ||
let tileWidth = screenSize.width / CGFloat(Self.numberOfColumns) | ||
let columns = [GridItem](repeating: GridItem(.flexible(), spacing: Layout.spacing1x), count: Self.numberOfColumns) | ||
|
||
LazyVGrid(columns: columns, alignment: .leading) { | ||
ForEach(viewModel.channels) { channel in | ||
let source = channel.source | ||
let preferredVideoQuality: VideoQuality = .auto | ||
let displayLabel = source.sourceId.displayLabel | ||
let viewId = "\(ChannelGridView.self).\(displayLabel)" | ||
VideoRendererView(source: source, | ||
isSelectedVideoSource: true, | ||
isSelectedAudioSource: true, | ||
showSourceLabel: false, | ||
showAudioIndicator: false, | ||
maxWidth: tileWidth, | ||
maxHeight: .infinity, | ||
accessibilityIdentifier: "ChannelGridViewVideoTile.\(source.sourceId.displayLabel)", | ||
preferredVideoQuality: preferredVideoQuality, | ||
subscriptionManager: channel.subscriptionManager, | ||
videoTracksManager: channel.videoTracksManager) | ||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center) | ||
.onAppear { | ||
ChannelGridViewModel.logger.debug("♼ Channel Grid view: Video view appear for \(source.sourceId)") | ||
Task { | ||
await channel.videoTracksManager.enableTrack(for: source, with: preferredVideoQuality, on: viewId) | ||
} | ||
} | ||
.onDisappear { | ||
ChannelGridViewModel.logger.debug("♼ Channel Grid view: Video view disappear for \(source.sourceId)") | ||
Task { | ||
await channel.videoTracksManager.disableTrack(for: source, on: viewId) | ||
} | ||
} | ||
.id(source.id) | ||
.id(channel.source.id) | ||
} | ||
} | ||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ChannelGridView(viewModel: ChannelGridViewModel(channels: [])) | ||
} |
22 changes: 22 additions & 0 deletions
22
rts-viewer-tvos/RTSViewer/ChannelGridView/ChannelGridViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// ChannelGridViewModel.swift | ||
// | ||
|
||
import Foundation | ||
import MillicastSDK | ||
import os | ||
import SwiftUI | ||
|
||
@MainActor | ||
final class ChannelGridViewModel: ObservableObject { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if no mutations it does not need to be ObservableObject and can be a struct? |
||
static let logger = Logger( | ||
subsystem: Bundle.main.bundleIdentifier!, | ||
category: String(describing: ChannelGridViewModel.self) | ||
) | ||
|
||
let channels: [SourcedChannel] | ||
|
||
init(channels: [SourcedChannel]) { | ||
self.channels = channels | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// ChannelView.swift | ||
// | ||
|
||
import DolbyIOUIKit | ||
import RTSCore | ||
import SwiftUI | ||
|
||
struct ChannelView: View { | ||
@ObservedObject private var viewModel: ChannelViewModel | ||
@ObservedObject private var themeManager = ThemeManager.shared | ||
|
||
private var theme: Theme { themeManager.theme } | ||
|
||
init(viewModel: ChannelViewModel) { | ||
self.viewModel = viewModel | ||
} | ||
|
||
var body: some View { | ||
NavigationView { | ||
ZStack { | ||
switch viewModel.state { | ||
case let .success(channels: channels): | ||
let viewModel = ChannelGridViewModel(channels: channels) | ||
ChannelGridView(viewModel: viewModel) | ||
case .loading: | ||
progressView | ||
case let .error(title: title, subtitle: subtitle, showLiveIndicator: showLiveIndicator): | ||
errorView(title: title, subtitle: subtitle, showLiveIndicator: showLiveIndicator) | ||
} | ||
} | ||
} | ||
.onAppear { | ||
UIApplication.shared.isIdleTimerDisabled = true | ||
viewModel.viewStreams() | ||
} | ||
.onDisappear { | ||
UIApplication.shared.isIdleTimerDisabled = false | ||
viewModel.endStream() | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private func errorView(title: String, subtitle: String?, showLiveIndicator: Bool) -> some View { | ||
ErrorView(title: title, subtitle: subtitle) | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
} | ||
|
||
@ViewBuilder | ||
private var progressView: some View { | ||
ProgressView() | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
} | ||
} | ||
|
||
#Preview { | ||
ChannelView(viewModel: ChannelViewModel(channels: .constant([]), onClose: {})) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the second
id
view modifier is redundant?