Minor tvOS fixes

This commit is contained in:
Arkadiusz Fal 2021-10-22 17:00:09 +02:00
parent 0e54cbcad0
commit bc065e282a
6 changed files with 25 additions and 17 deletions

View File

@ -255,14 +255,18 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
return searchQuery return searchQuery
} }
static func assetURLFrom(instance: Instance, url: URL) -> URL? { static func proxiedAsset(instance: Instance, asset: AVURLAsset) -> AVURLAsset? {
guard let instanceURLComponents = URLComponents(string: instance.url), guard let instanceURLComponents = URLComponents(string: instance.url),
var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return nil } var urlComponents = URLComponents(url: asset.url, resolvingAgainstBaseURL: false) else { return nil }
urlComponents.scheme = instanceURLComponents.scheme urlComponents.scheme = instanceURLComponents.scheme
urlComponents.host = instanceURLComponents.host urlComponents.host = instanceURLComponents.host
return urlComponents.url guard let url = urlComponents.url else {
return nil
}
return AVURLAsset(url: url)
} }
static func extractVideo(_ json: JSON) -> Video { static func extractVideo(_ json: JSON) -> Video {

View File

@ -1,7 +1,6 @@
import Foundation import Foundation
import Siesta import Siesta
import SwiftUI import SwiftUI
import AVFoundation
extension PlayerModel { extension PlayerModel {
var isLoadingAvailableStreams: Bool { var isLoadingAvailableStreams: Bool {
@ -104,8 +103,8 @@ extension PlayerModel {
stream.instance = instance stream.instance = instance
if instance.app == .invidious { if instance.app == .invidious {
stream.audioAsset = AVURLAsset(url: InvidiousAPI.assetURLFrom(instance: instance, url: stream.audioAsset.url)!) stream.audioAsset = InvidiousAPI.proxiedAsset(instance: instance, asset: stream.audioAsset)
stream.videoAsset = AVURLAsset(url: InvidiousAPI.assetURLFrom(instance: instance, url: stream.videoAsset.url)!) stream.videoAsset = InvidiousAPI.proxiedAsset(instance: instance, asset: stream.videoAsset)
} }
return stream return stream

View File

@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/Alamofire/Alamofire.git", "repositoryURL": "https://github.com/Alamofire/Alamofire.git",
"state": { "state": {
"branch": null, "branch": null,
"revision": "f96b619bcb2383b43d898402283924b80e2c4bae", "revision": "d120af1e8638c7da36c8481fd61a66c0c08dc4fc",
"version": "5.4.3" "version": "5.4.4"
} }
}, },
{ {

View File

@ -42,7 +42,7 @@ final class PlayerViewController: UIViewController {
var playerQueueInfoViewController: UIHostingController<AnyView> { var playerQueueInfoViewController: UIHostingController<AnyView> {
let controller = UIHostingController(rootView: let controller = UIHostingController(rootView:
AnyView( AnyView(
NowPlayingView(infoViewController: true) NowPlayingView(inInfoViewController: true)
.frame(maxHeight: 600) .frame(maxHeight: 600)
.environmentObject(playerModel) .environmentObject(playerModel)
) )

View File

@ -13,7 +13,7 @@ struct AccountSelectionView: View {
var body: some View { var body: some View {
Section(header: Text(showHeader ? "Current Account" : "")) { Section(header: Text(showHeader ? "Current Account" : "")) {
Button(accountButtonTitle(account: accountsModel.current)) { Button(accountButtonTitle(account: accountsModel.current, long: true)) {
if let account = nextAccount { if let account = nextAccount {
accountsModel.setCurrent(account) accountsModel.setCurrent(account)
} }
@ -40,11 +40,13 @@ struct AccountSelectionView: View {
allAccounts.next(after: accountsModel.current) allAccounts.next(after: accountsModel.current)
} }
func accountButtonTitle(account: Account! = nil) -> String { func accountButtonTitle(account: Account! = nil, long: Bool = false) -> String {
guard account != nil else { guard account != nil else {
return "Not selected" return "Not selected"
} }
return instances.count > 1 ? "\(account.description)\(account.instance.shortDescription)" : account.description let instanceDescription = long ? account.instance.longDescription : account.instance.description
return instances.count > 1 ? "\(account.description)\(instanceDescription)" : account.description
} }
} }

View File

@ -1,12 +1,12 @@
import SwiftUI import SwiftUI
struct NowPlayingView: View { struct NowPlayingView: View {
var infoViewController = false var inInfoViewController = false
@EnvironmentObject<PlayerModel> private var player @EnvironmentObject<PlayerModel> private var player
var body: some View { var body: some View {
if infoViewController { if inInfoViewController {
content content
.background(.thinMaterial) .background(.thinMaterial)
.mask(RoundedRectangle(cornerRadius: 24)) .mask(RoundedRectangle(cornerRadius: 24))
@ -18,7 +18,7 @@ struct NowPlayingView: View {
var content: some View { var content: some View {
ScrollView(.vertical) { ScrollView(.vertical) {
VStack(alignment: .leading) { VStack(alignment: .leading) {
if !infoViewController, let item = player.currentItem { if !inInfoViewController, let item = player.currentItem {
Group { Group {
header("Now Playing") header("Now Playing")
@ -93,7 +93,7 @@ struct NowPlayingView: View {
func header(_ text: String) -> some View { func header(_ text: String) -> some View {
Text(text) Text(text)
.font(.title3.bold()) .font((inInfoViewController ? Font.system(size: 40) : .title3).bold())
.foregroundColor(.secondary) .foregroundColor(.secondary)
.padding(.leading, 40) .padding(.leading, 40)
} }
@ -103,5 +103,8 @@ struct NowPlayingView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
NowPlayingView() NowPlayingView()
.injectFixtureEnvironmentObjects() .injectFixtureEnvironmentObjects()
NowPlayingView(inInfoViewController: true)
.injectFixtureEnvironmentObjects()
} }
} }