Merge pull request 'feat(mobile): add native AirPlay and Cast output picker' (#48) from t3/mobile-native-airplay-cast-ui into t3/android-layout-and-colors
Reviewed-on: #48
This commit was merged in pull request #48.
This commit is contained in:
commit
09c821f563
11 files changed
+188
-18
No files matched your search
@@ -1,7 +1,7 @@
|
||||
ios/
|
||||
android/
|
||||
/ios/
|
||||
/android/
|
||||
# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
|
||||
# The following patterns were generated by expo-cli
|
||||
|
||||
expo-env.d.ts
|
||||
# @end expo-cli
|
||||
# @end expo-cli
|
||||
@@ -30,6 +30,7 @@ import { api } from "@otunes/convex/_generated/api"
|
||||
import { playbackFormat } from "@otunes/convex/playback-stream"
|
||||
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import { AudioOutputButton } from "@/components/audio-output-button"
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
import { MarqueeText } from "@/components/marquee-text"
|
||||
import {
|
||||
@@ -431,21 +432,10 @@ export default function PlayerScreen() {
|
||||
color={colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
disabled
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={Platform.OS === "ios" ? "AirPlay" : "Cast"}
|
||||
accessibilityState={{ disabled: true }}
|
||||
style={[styles.queueButton, styles.unavailable]}
|
||||
>
|
||||
<PlayerSymbol
|
||||
name="airplay.audio"
|
||||
fallback={{ material: "cast" }}
|
||||
size={27}
|
||||
weight="semibold"
|
||||
color={colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
<AudioOutputButton
|
||||
color={colors.foreground}
|
||||
style={styles.queueButton}
|
||||
/>
|
||||
<Pressable
|
||||
onPress={toggleQueue}
|
||||
hitSlop={8}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import {
|
||||
requireNativeView,
|
||||
requireOptionalNativeModule,
|
||||
type NativeModule,
|
||||
} from "expo"
|
||||
import {
|
||||
Platform,
|
||||
Pressable,
|
||||
type StyleProp,
|
||||
type ViewProps,
|
||||
type ViewStyle,
|
||||
} from "react-native"
|
||||
|
||||
import { PlayerSymbol } from "@/components/player-symbol"
|
||||
import { showError } from "@/lib/toast"
|
||||
|
||||
type AudioOutputModule = NativeModule & {
|
||||
showPicker: () => Promise<boolean>
|
||||
}
|
||||
|
||||
const audioOutput =
|
||||
requireOptionalNativeModule<AudioOutputModule>("AudioOutput")
|
||||
const AirPlayPicker =
|
||||
Platform.OS === "ios" && audioOutput
|
||||
? requireNativeView<ViewProps & { tint: string }>("AudioOutput")
|
||||
: null
|
||||
|
||||
export function AudioOutputButton({
|
||||
color,
|
||||
style,
|
||||
}: {
|
||||
color: string
|
||||
style: StyleProp<ViewStyle>
|
||||
}) {
|
||||
if (AirPlayPicker) {
|
||||
return <AirPlayPicker tint={color} style={style} />
|
||||
}
|
||||
|
||||
const available =
|
||||
Platform.OS === "android" && Platform.Version >= 33 && audioOutput !== null
|
||||
|
||||
async function showPicker() {
|
||||
try {
|
||||
if (!(await audioOutput?.showPicker())) {
|
||||
showError("Audio output selection is unavailable on this device.")
|
||||
}
|
||||
} catch {
|
||||
showError("Audio output selection could not be opened.")
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
onPress={showPicker}
|
||||
disabled={!available}
|
||||
hitSlop={8}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={Platform.OS === "ios" ? "AirPlay" : "Audio output"}
|
||||
accessibilityState={{ disabled: !available }}
|
||||
style={[style, !available && { opacity: 0.35 }]}
|
||||
>
|
||||
<PlayerSymbol
|
||||
name="airplay.audio"
|
||||
fallback={{ material: "cast" }}
|
||||
size={27}
|
||||
weight="semibold"
|
||||
color={color}
|
||||
/>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
/android/build/
|
||||
@@ -0,0 +1,15 @@
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'expo-module-gradle-plugin'
|
||||
}
|
||||
|
||||
group = 'expo.modules.audiooutput'
|
||||
version = '1.0.0'
|
||||
|
||||
android {
|
||||
namespace 'expo.modules.audiooutput'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.mediarouter:mediarouter:1.8.1'
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Android 13's switcher helper checks for a system broadcast receiver. -->
|
||||
<queries>
|
||||
<package android:name="com.android.systemui" />
|
||||
<intent>
|
||||
<action android:name="com.android.settings.panel.action.MEDIA_OUTPUT" />
|
||||
</intent>
|
||||
</queries>
|
||||
</manifest>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package expo.modules.audiooutput
|
||||
|
||||
import android.os.Build
|
||||
import androidx.mediarouter.app.SystemOutputSwitcherDialogController
|
||||
import expo.modules.kotlin.functions.Queues
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
|
||||
class AudioOutputModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("AudioOutput")
|
||||
|
||||
AsyncFunction("showPicker") {
|
||||
val activity = appContext.currentActivity
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || activity == null) {
|
||||
false
|
||||
} else {
|
||||
// AndroidX handles Android 13's system intent and Android 14+'s public API.
|
||||
SystemOutputSwitcherDialogController.showDialog(activity)
|
||||
}
|
||||
}.runOnQueue(Queues.MAIN)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"platforms": ["apple", "android"],
|
||||
"apple": {
|
||||
"modules": ["AudioOutputModule"]
|
||||
},
|
||||
"android": {
|
||||
"modules": ["expo.modules.audiooutput.AudioOutputModule"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'AudioOutput'
|
||||
s.version = '1.0.0'
|
||||
s.summary = 'Native audio output selection for oTunes'
|
||||
s.description = s.summary
|
||||
s.license = { :type => 'MIT' }
|
||||
s.author = 'oTunes'
|
||||
s.homepage = 'https://otunes.abunchofknowitalls.com'
|
||||
s.platforms = { :ios => '16.4' }
|
||||
s.swift_version = '5.9'
|
||||
s.source = { :git => '' }
|
||||
s.static_framework = true
|
||||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
|
||||
s.dependency 'ExpoModulesCore'
|
||||
s.frameworks = 'AVKit'
|
||||
s.source_files = '**/*.swift'
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
import AVKit
|
||||
import ExpoModulesCore
|
||||
|
||||
public class AudioOutputModule: Module {
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("AudioOutput")
|
||||
|
||||
View(AudioOutputView.self) {
|
||||
Prop("tint") { (view: AudioOutputView, color: UIColor) in
|
||||
view.picker.tintColor = color
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class AudioOutputView: ExpoView {
|
||||
let picker = AVRoutePickerView()
|
||||
|
||||
required init(appContext: AppContext? = nil) {
|
||||
super.init(appContext: appContext)
|
||||
picker.prioritizesVideoDevices = false
|
||||
picker.backgroundColor = .clear
|
||||
addSubview(picker)
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
picker.frame = bounds
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "otunes-audio-output",
|
||||
"version": "1.0.0",
|
||||
"private": true
|
||||
}
|
||||
Reference in new issue
Block a user