jwplayer / jwplayer-react-native

MIT License
32 stars 9 forks source link

[BUG][IOS] When multiple audio tracks are provided default audio track is not working #64

Open fdobre opened 4 months ago

fdobre commented 4 months ago

Describe the bug

"@jwplayer/jwplayer-react-native": "^1.0.1",
"react-native": "0.72.14"

When providing multiple audio tracks video has absolutely no sound.

After switching to another track sound works but switching back to the default track triggers an 1008 error.

Multiple audio tracks support doesn't have the above issue in Android.

To Reproduce

  1. Use a video that has at least 2 audio tracks.
  2. Play the video.
  3. Observe there is no sound even if the default track is active in the audio tracks menu
  4. Switch to another audio track
  5. Observe it has sound
  6. Switch back to the default track
  7. There is some loader showing and after that a 1008 error.

Expected behavior Audio tracks should work as in Android. Default audio track should have sound and when switching back to the default audio track there should be no error and sound should work.

AmitaiB commented 4 months ago

@fdobre Hey, thank you for reporting this issue. Can you share your player configuration/setup implementation? This can happen if no audio track is designated the default.

fdobre commented 3 months ago

@AmitaiB

const memoizedTracks = useMemo<Track[]>(() => {
      const tracks: Track[] = (captions || [])?.map(item => {
        return {
          file: item?.file ?? '',
          label: item?.label ?? '',
          kind: 'captions',
          default:
            (item?.languageCode || '').toLowerCase() === languageCode
              ? true
              : isAndroid
              ? false
              : undefined
        };
      });
      if (thumbnailPreviews) {
        tracks.push({
          file: thumbnailPreviews,
          kind: 'thumbnails',
          label: 'thumbnails'
        });
      }
      return tracks;
    }, [languageCode, captions, thumbnailPreviews]);

    const playlistItem = useMemo(
      () => ({
        image,
        file: hlsUrl,
        tracks: memoizedTracks ?? []
      }),
      [hlsUrl, image, memoizedTracks]
    );

const jwConfig: Config = useMemo(
      () => ({
        license: isIOS
          ? config.jwPlayerIOSLicense
          : config.jwPlayerAndroidLicense,
        enableLockScreenControls: false, // iOS only
        // Having PiP enabled on Android triggers a crash if advertisments (pre-rolls) are also enabled, retest this after JWP update
        pipEnabled: isIOS,
        backgroundAudioEnabled: false,
        autostart: true,
        playlist: [playlistItem],
        styling: {
          menuStyle: {
            backgroundColour: 'rgba(51, 51, 51, 1)',
            fontColor: 'rgba(255, 255, 255, 0.8)'
          },
          colours: {
            timeslider: {
              progress: '#ff1541',
              rail: 'rgba(255, 255, 255, 0.3)'
            }
          }
        },
        advertising: isPremium
          ? undefined
          : {
              adClient: 'vast',
              adSchedule: [{ offset: 'pre', tag: vastTag }]
            },
        landscapeOnFullScreen: true,
        fullScreenOnLandscape: isAndroid,
        portraitOnExitFullScreen: true, // Supported for Android only
        exitFullScreenOnPortrait: isAndroid,
        hideUiGroups: ['casting_menu'],
        hideCastIcon: isAndroid ? true : undefined // We had to add a patch in RN-JWPlayer to hide the cast button
      }),
      [playlistItem, isPremium, vastTag]
    );

Hope this helps. If any other additional info is needed please let me know.