mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
extended cast controls on android
This commit is contained in:
6
app.json
6
app.json
@@ -68,6 +68,12 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
"./plugins/withAndroidMainActivityAttributes",
|
||||
{
|
||||
"com.reactnative.googlecast.RNGCExpandedControllerActivity": true
|
||||
}
|
||||
],
|
||||
[
|
||||
"expo-build-properties",
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ import CastContext, {
|
||||
useRemoteMediaClient,
|
||||
} from "react-native-google-cast";
|
||||
import { Button } from "./Button";
|
||||
import { isCancel } from "axios";
|
||||
|
||||
interface Props extends React.ComponentProps<typeof Button> {
|
||||
item?: BaseItemDto | null;
|
||||
@@ -18,7 +19,7 @@ interface Props extends React.ComponentProps<typeof Button> {
|
||||
export const PlayButton: React.FC<Props> = ({ item, url, ...props }) => {
|
||||
const { showActionSheetWithOptions } = useActionSheet();
|
||||
const client = useRemoteMediaClient();
|
||||
const { setCurrentlyPlayingState } = usePlayback();
|
||||
const { setCurrentlyPlayingState, isPlaying, currentlyPlaying } = usePlayback();
|
||||
|
||||
const onPress = async () => {
|
||||
if (!url || !item) return;
|
||||
@@ -37,12 +38,22 @@ export const PlayButton: React.FC<Props> = ({ item, url, ...props }) => {
|
||||
cancelButtonIndex,
|
||||
},
|
||||
async (selectedIndex: number | undefined) => {
|
||||
const isOpeningCurrentlyPlayingMedia = isPlaying
|
||||
&& currentlyPlaying?.item?.Name
|
||||
&& currentlyPlaying?.item?.Name === item?.Name
|
||||
switch (selectedIndex) {
|
||||
case 0:
|
||||
await CastContext.getPlayServicesState().then((state) => {
|
||||
if (state && state !== PlayServicesState.SUCCESS)
|
||||
CastContext.showPlayServicesErrorDialog(state);
|
||||
else {
|
||||
// If we're opening a currently playing item, don't restart the media.
|
||||
// Instead just open controls
|
||||
console.log({ isOpeningCurrentlyPlayingMedia, currentlyPlaying })
|
||||
if (isOpeningCurrentlyPlayingMedia) {
|
||||
CastContext.showExpandedControls();
|
||||
return;
|
||||
}
|
||||
client.loadMedia({
|
||||
mediaInfo: {
|
||||
contentUrl: url,
|
||||
@@ -54,6 +65,14 @@ export const PlayButton: React.FC<Props> = ({ item, url, ...props }) => {
|
||||
},
|
||||
},
|
||||
startTime: 0,
|
||||
}).then(() => {
|
||||
if (isOpeningCurrentlyPlayingMedia) {
|
||||
return
|
||||
}
|
||||
setCurrentlyPlayingState({ item, url });
|
||||
CastContext.showExpandedControls();
|
||||
}).catch(e => {
|
||||
console.log({ e })
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
42
plugins/withAndroidMainActivityAttributes.js
Normal file
42
plugins/withAndroidMainActivityAttributes.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const { withAndroidManifest } = require("@expo/config-plugins");
|
||||
|
||||
function addAttributesToMainActivity(androidManifest, attributes) {
|
||||
const { manifest } = androidManifest;
|
||||
|
||||
if (!Array.isArray(manifest["application"])) {
|
||||
console.warn("withAndroidMainActivityAttributes: No application array in manifest?");
|
||||
return androidManifest;
|
||||
}
|
||||
|
||||
const application = manifest["application"].find(
|
||||
(item) => item.$["android:name"] === ".MainApplication"
|
||||
);
|
||||
if (!application) {
|
||||
console.warn("withAndroidMainActivityAttributes: No .MainApplication?");
|
||||
return androidManifest;
|
||||
}
|
||||
|
||||
if (!Array.isArray(application["activity"])) {
|
||||
console.warn("withAndroidMainActivityAttributes: No activity array in .MainApplication?");
|
||||
return androidManifest;
|
||||
}
|
||||
|
||||
const activity = application["activity"].find(
|
||||
(item) => item.$["android:name"] === ".MainActivity"
|
||||
);
|
||||
if (!activity) {
|
||||
console.warn("withAndroidMainActivityAttributes: No .MainActivity?");
|
||||
return androidManifest;
|
||||
}
|
||||
|
||||
activity.$ = { ...activity.$, ...attributes };
|
||||
|
||||
return androidManifest;
|
||||
}
|
||||
|
||||
module.exports = function withAndroidMainActivityAttributes(config, attributes) {
|
||||
return withAndroidManifest(config, (config) => {
|
||||
config.modResults = addAttributesToMainActivity(config.modResults, attributes);
|
||||
return config;
|
||||
});
|
||||
};
|
||||
@@ -181,7 +181,7 @@ export const PlaybackProvider: React.FC<{ children: ReactNode }> = ({
|
||||
useEffect(() => {
|
||||
if (!deviceId || !api?.accessToken) return;
|
||||
|
||||
const url = `wss://${api?.basePath
|
||||
const url = `ws://${api?.basePath
|
||||
.replace("https://", "")
|
||||
.replace("http://", "")}/socket?api_key=${
|
||||
api?.accessToken
|
||||
|
||||
Reference in New Issue
Block a user