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

Fix silent iOS playback when device is muted while running the example application #338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 16 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Platform, Button } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { SourceType } from 'bitmovin-player-react-native';
import { AudioSession, SourceType } from 'bitmovin-player-react-native';
import ExamplesList from './screens/ExamplesList';
import BasicAds from './screens/BasicAds';
import BasicAnalytics from './screens/BasicAnalytics';
Expand Down Expand Up @@ -63,6 +63,20 @@ const RootStack = createNativeStackNavigator();
const isTVOS = Platform.OS === 'ios' && Platform.isTV;

export default function App() {
useEffect(() => {
// iOS audio session category must be set to `playback` first, otherwise playback
// will have no audio when the device is silenced.
// This is also required to make Picture in Picture work on iOS.
//
// Usually it's desireable to set the audio's category only once during your app's main component
// initialization. This way you can guarantee that your app's audio category is properly
// configured throughout the whole lifecycle of the application.
AudioSession.setCategory('playback').catch((error) => {
// Handle any native errors that might occur while setting the audio's category.
console.log("Failed to set app's audio category to `playback`:\n", error);
});
});

const stackParams = {
data: [
{
Expand Down
14 changes: 0 additions & 14 deletions example/src/screens/BasicPictureInPicture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
usePlayer,
PlayerView,
SourceType,
AudioSession,
PictureInPictureEnterEvent,
PictureInPictureExitEvent,
PlayerViewConfig,
Expand Down Expand Up @@ -51,19 +50,6 @@ export default function BasicPictureInPicture({

useFocusEffect(
useCallback(() => {
// iOS audio session must be set to `playback` first otherwise PiP mode won't work.
//
// Usually it's desireable to set the audio's category only once during your app's main component
// initialization. This way you can guarantee that your app's audio category is properly
// configured throughout the whole lifecycle of the application.
AudioSession.setCategory('playback').catch((error) => {
// Handle any native errors that might occur while setting the audio's category.
console.log(
"[BasicPictureInPicture] Failed to set app's audio category to `playback`:\n",
error
);
});

// Load desired source configuration
player.load({
url:
Expand Down