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

[BUG]: MixWithOthers iOS not work for first load #4027

Open
krisnapy opened this issue Jul 24, 2024 · 5 comments
Open

[BUG]: MixWithOthers iOS not work for first load #4027

krisnapy opened this issue Jul 24, 2024 · 5 comments
Labels
Accepted Issue is confirmed and accepted by maintainers team bug Platform: iOS

Comments

@krisnapy
Copy link

krisnapy commented Jul 24, 2024

Version

6.4.2

What platforms are you having the problem on?

iOS

System Version

iOS 17.5.1

On what device are you experiencing the issue?

Real device

Architecture

Old architecture

What happened?

External audio such as Spotify stops when the video has been played even if I set MixWithOthers to “mix”, but when the audio is played again, the audio does not stop. I thought it would stop when first load/play.

RPReplay_Final1721793736.online-video-cutter.com.mp4

Reproduction

Reproduction

Step to reproduce this bug are:

Component:

import React from 'react'
import Video, { IgnoreSilentSwitchType, MixWithOthersType } from 'react-native-video'

export function LandingScreen(): JSX.Element {
  return (
    <Video
      style={{ flex: 1 }}
      resizeMode="contain"
      source={{ uri: 'https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerMeltdowns.mp4' }}
      ignoreSilentSwitch={IgnoreSilentSwitchType.IGNORE}
      mixWithOthers={MixWithOthersType.MIX}
      controls
    />
  )
}

AppDelegate:

#import "AppDelegate.h"
#import "RNBootSplash.h"
#import <Firebase.h>
#import <React/RCTLinkingManager.h>
#import "RNFBMessagingModule.h"

#import <React/RCTBundleURLProvider.h>
#import <AVFoundation/AVFoundation.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // RN Firebase
  [FIRApp configure];

  self.moduleName = @"factum";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.

  [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];

  self.initialProps = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:launchOptions];

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

// RNBootSplash
- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
                          moduleName:(NSString *)moduleName
                           initProps:(NSDictionary *)initProps {
  UIView *rootView = [super createRootViewWithBridge:bridge
                                          moduleName:moduleName
                                           initProps:initProps];

  [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView];

  return rootView;
}

// Deep Links
- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

// Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
  return [RCTLinkingManager
            application:application
            continueUserActivity:userActivity
            restorationHandler:restorationHandler
         ];
}

@end
@krisnapy krisnapy added the bug label Jul 24, 2024
@moskalakamil
Copy link
Member

Hi @krisnapy, thanks for sharing issue! We'll try to fix it as fast as possible!

Copy link

github-actions bot commented Sep 5, 2024

This issue is stale because it has been open for 30 days with no activity. If there won't be any activity in the next 14 days, this issue will be closed automatically.

@github-actions github-actions bot added the stale Closed due to inactivity or lack or resources label Sep 5, 2024
@freeboub
Copy link
Collaborator

freeboub commented Sep 6, 2024

Sorry for very long answer time. It looks like something easy to fix (1 line):

I think following patch should be enough to fix the issue:

diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift
index 345acbf0..4b002828 100644
--- a/ios/Video/RCTVideo.swift
+++ b/ios/Video/RCTVideo.swift
@@ -753,6 +753,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
     @objc
     func setMixWithOthers(_ mixWithOthers: String?) {
         _mixWithOthers = mixWithOthers
+        RCTPlayerOperations.configureAudio(ignoreSilentSwitch: _ignoreSilentSwitch, mixWithOthers: _mixWithOthers, audioOutput: _audioOutput)
         applyModifiers()
     }

@freeboub
Copy link
Collaborator

freeboub commented Sep 6, 2024

hum, that is not enough ...
If we define only mixWithOther, there is no audio output at all ...
@KrzysztofMoch It would be great to integrate this change as part of: https://github.com/TheWidlarzGroup/react-native-video/pull/3850/files
I think you already fix the issue I see in your PR, but as I don't have real iphone yet, I cannot test properly ...

@freeboub
Copy link
Collaborator

freeboub commented Sep 6, 2024

I also wonder if configureAudio (or your new function) should be called inside applyModifiers ? but I am not sure ...

@freeboub freeboub added Platform: iOS Accepted Issue is confirmed and accepted by maintainers team and removed stale Closed due to inactivity or lack or resources labels Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue is confirmed and accepted by maintainers team bug Platform: iOS
Projects
None yet
Development

No branches or pull requests

3 participants