Skip to content
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

Add playback HUD support #893

Merged
merged 27 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bb90e6c
Add setting to display playback HUD
defagos May 23, 2024
227f5bc
Add playback HUD customization settings
defagos May 23, 2024
0cff672
Improve implementation
defagos May 23, 2024
8050d61
Provide default HUD settings
defagos May 24, 2024
ff84d3a
Tweak font size ranges
defagos May 24, 2024
745e31c
Improve layout
defagos May 24, 2024
ce987f2
Improve number edition
defagos May 24, 2024
ee7ebf2
Improve setting management on tvOS
defagos May 24, 2024
64531dd
Remove unused formatter
defagos May 24, 2024
c3eed90
Remove currently superfluous focusable
defagos May 24, 2024
8aeeb01
Add translation key
defagos May 24, 2024
bb39673
Fix simple player layout
defagos May 24, 2024
3569674
Use standard picker appearance on iOS
defagos May 24, 2024
0134e75
Improve footer
defagos May 24, 2024
c9f9a7d
Fix reset button appearance on tvOS
defagos May 24, 2024
37b9677
Improve constant consistency
defagos May 24, 2024
0a5730a
Improve default HUD position
defagos May 24, 2024
0f1baf0
Fix default value registration
defagos May 24, 2024
23f8ec3
Fix different font scaling on device and simulator
defagos May 24, 2024
ac80c94
Remove extra large support
defagos May 24, 2024
e54c995
Improve sizes on tvOS
defagos May 24, 2024
3a2005f
Fix linting issues
defagos May 24, 2024
ec10bb4
Improve implementation
defagos May 24, 2024
359a8ad
Remove superfluous explicit values
defagos May 24, 2024
042b0f3
Use consistent style
defagos May 24, 2024
40c4771
Disable playback HUD on macOS to avoid sandboxing issues
defagos May 24, 2024
f5f5774
Revert "Disable playback HUD on macOS to avoid sandboxing issues"
defagos May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Demo/Pillarbox-demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
6FDB51CB2A4042B2001F430F /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FDB51CA2A4042B2001F430F /* Router.swift */; };
6FE324B329E4657D007501CF /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE324B229E4657D007501CF /* View.swift */; };
6FED426B2A96F4D3004D7724 /* TransitionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FED426A2A96F4D3004D7724 /* TransitionView.swift */; };
6FF7C9832C0084BC00FBDADB /* PlaybackHudFontSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FF7C9822C0084BC00FBDADB /* PlaybackHudFontSize.swift */; };
6FF7C9852C0084CE00FBDADB /* PlaybackHudColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FF7C9842C0084CE00FBDADB /* PlaybackHudColor.swift */; };
6FF7C9872C0084DD00FBDADB /* SeekBehaviorSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FF7C9862C0084DD00FBDADB /* SeekBehaviorSetting.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -186,6 +189,9 @@
6FDB51CA2A4042B2001F430F /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
6FE324B229E4657D007501CF /* View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
6FED426A2A96F4D3004D7724 /* TransitionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransitionView.swift; sourceTree = "<group>"; };
6FF7C9822C0084BC00FBDADB /* PlaybackHudFontSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackHudFontSize.swift; sourceTree = "<group>"; };
6FF7C9842C0084CE00FBDADB /* PlaybackHudColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackHudColor.swift; sourceTree = "<group>"; };
6FF7C9862C0084DD00FBDADB /* SeekBehaviorSetting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeekBehaviorSetting.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -294,8 +300,11 @@
children = (
6F59E84B29CF31E10093E6FB /* Media.swift */,
6F59E84C29CF31E10093E6FB /* MediaDescription.swift */,
6FF7C9842C0084CE00FBDADB /* PlaybackHudColor.swift */,
6FF7C9822C0084BC00FBDADB /* PlaybackHudFontSize.swift */,
6F59E84A29CF31E10093E6FB /* Playlist.swift */,
6F59E84929CF31E10093E6FB /* RadioChannel.swift */,
6FF7C9862C0084DD00FBDADB /* SeekBehaviorSetting.swift */,
6F59E84729CF31E10093E6FB /* ServerSetting.swift */,
6F59E84829CF31E10093E6FB /* Template.swift */,
6F59E84629CF31E10093E6FB /* Vendor.swift */,
Expand Down Expand Up @@ -642,7 +651,9 @@
0EF2A5492B44500800F01804 /* SettingsBundle.swift in Sources */,
6FAD51142B331AAD0078FE08 /* SingleView.swift in Sources */,
6F7EAA552B17755C00194D03 /* TrackingProgressTutorial~ios.swift in Sources */,
6FF7C9852C0084CE00FBDADB /* PlaybackHudColor.swift in Sources */,
6F59E88229CF31E10093E6FB /* Media.swift in Sources */,
6FF7C9872C0084DD00FBDADB /* SeekBehaviorSetting.swift in Sources */,
6F59E87E29CF31E10093E6FB /* ServerSetting.swift in Sources */,
6F59E87929CF31E10093E6FB /* SearchView.swift in Sources */,
6F59E88029CF31E10093E6FB /* RadioChannel.swift in Sources */,
Expand All @@ -659,6 +670,7 @@
0E48F3FC2B2DBAD4001982BB /* CustomNavigationLink.swift in Sources */,
6FD407892B189C0600D34BD1 /* TrackingVisibilityTutorial~ios.swift in Sources */,
0ECC5AD52A517A4C0064E701 /* PlaybackSlider~ios.swift in Sources */,
6FF7C9832C0084BC00FBDADB /* PlaybackHudFontSize.swift in Sources */,
6F12A9522BD2B8A300AD6DDB /* IntegratingWithControlCenter.swift in Sources */,
0EE2A3B02B29F82200BAAD65 /* CustomSection.swift in Sources */,
6F59E89929CF31E20093E6FB /* PlaybackView.swift in Sources */,
Expand Down
42 changes: 42 additions & 0 deletions Demo/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
},
"Automatic" : {

},
"Blue" : {

defagos marked this conversation as resolved.
Show resolved Hide resolved
},
"Both" : {

Expand All @@ -78,6 +81,9 @@
},
"Clear URL cache" : {

},
"Color" : {

},
"Content displayed" : {

Expand All @@ -99,15 +105,24 @@
},
"Embeddings" : {

},
"Enabled" : {

},
"Enter URL or URN" : {

},
"Examples" : {

},
"Font size" : {

},
"GitHub" : {

},
"Green" : {

},
"Immediate" : {

Expand Down Expand Up @@ -150,6 +165,9 @@
},
"Play" : {

},
"Playback HUD" : {

},
"Player" : {

Expand All @@ -162,6 +180,12 @@
},
"Project" : {

},
"Red" : {

},
"Reset" : {

},
"Search" : {

Expand All @@ -177,6 +201,9 @@
},
"Showcase" : {

},
"Shows a video overlay displaying various playback-related statistics." : {

},
"Simulate memory warning" : {

Expand Down Expand Up @@ -213,12 +240,27 @@
},
"Use a proxy tool to observe events." : {

},
"Value" : {

},
"Version information" : {

},
"Web" : {

},
"White" : {

},
"X offset" : {

},
"Y offset" : {

},
"Yellow" : {

}
},
"version" : "1.0"
Expand Down
2 changes: 1 addition & 1 deletion Demo/Sources/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
// swiftlint:disable:next discouraged_optional_collection
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
try? AVAudioSession.sharedInstance().setCategory(.playback)
UserDefaults.standard.registerDefaults()
UserDefaults.registerDefaults()
configureShowTime()
configureDataProvider()
configureAnalytics()
Expand Down
4 changes: 2 additions & 2 deletions Demo/Sources/ContentLists/ContentListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private struct LoadedView: View {
let contents: [ContentListViewModel.Content]
@EnvironmentObject private var router: Router

@AppStorage(UserDefaults.serverSettingKey)
@AppStorage(UserDefaults.DemoSettingKey.serverSetting.rawValue)
private var serverSetting: ServerSetting = .ilProduction

var body: some View {
Expand Down Expand Up @@ -65,7 +65,7 @@ private struct LoadedView: View {
private struct ContentCell: View {
let content: ContentListViewModel.Content

@AppStorage(UserDefaults.serverSettingKey)
@AppStorage(UserDefaults.DemoSettingKey.serverSetting.rawValue)
private var serverSetting: ServerSetting = .ilProduction

@EnvironmentObject private var router: Router
Expand Down
2 changes: 1 addition & 1 deletion Demo/Sources/ContentLists/ContentListsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

// Behavior: h-exp, v-exp
struct ContentListsView: View {
@AppStorage(UserDefaults.serverSettingKey)
@AppStorage(UserDefaults.DemoSettingKey.serverSetting.rawValue)
private var selectedServerSetting: ServerSetting = .ilProduction

var body: some View {
Expand Down
15 changes: 15 additions & 0 deletions Demo/Sources/Model/PlaybackHudColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

import Foundation

enum PlaybackHudColor: Int {
case yellow
case green
case red
case blue
case white
}
77 changes: 77 additions & 0 deletions Demo/Sources/Model/PlaybackHudFontSize.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

import Foundation
import UIKit

enum PlaybackHudFontSize: Int, CaseIterable {
case small
case `default`
case large

private static let smallValue = constant(iOS: 9, tvOS: 30)
private static let defaultValue = constant(iOS: 18, tvOS: 40)
private static let largeValue = constant(iOS: 27, tvOS: 50)

var name: String {
switch self {
case .small:
return "Small"
case .default:
return "Default"
case .large:
return "Large"
}
}

var rawValue: Int {
let value = Self.value(from: self)
return Self.scaledValue(fromValue: value)
}

init?(rawValue: Int) {
let value = Self.value(fromScaledValue: rawValue)
self = Self.size(fromValue: value)
}

private static func value(from size: Self) -> Int {
switch size {
case .small:
return smallValue
case .default:
return defaultValue
case .large:
return largeValue
}
}

private static func size(fromValue value: Int) -> Self {
switch value {
case smallValue:
return .small
case largeValue:
return .large
default:
return .default
}
}

private static func scaledValue(fromValue value: Int) -> Int {
#if targetEnvironment(simulator)
value
#else
value * Int(UIScreen.main.scale)
#endif
}

private static func value(fromScaledValue value: Int) -> Int {
#if targetEnvironment(simulator)
value
#else
value / Int(UIScreen.main.scale)
#endif
}
}
13 changes: 13 additions & 0 deletions Demo/Sources/Model/SeekBehaviorSetting.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

import Foundation

@objc
enum SeekBehaviorSetting: Int {
case immediate
case deferred
}
9 changes: 8 additions & 1 deletion Demo/Sources/Players/SimplePlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct SimplePlayerView: View {

var body: some View {
ZStack {
VideoView(player: player)
videoView()
progressView()
playbackButton()
}
Expand All @@ -30,6 +30,13 @@ struct SimplePlayerView: View {
.tracked(name: "simple-player")
}

@ViewBuilder
private func videoView() -> some View {
VideoView(player: player)
.background(.black)
.ignoresSafeArea()
}

@ViewBuilder
private func progressView() -> some View {
ProgressView()
Expand Down
Loading