albemala / native_video_player

A Flutter widget to play videos on iOS and Android using a native implementation.
MIT License
18 stars 13 forks source link

On iOS, there is no audio when playing videos #22

Open indacurdev opened 3 months ago

indacurdev commented 3 months ago

I'm trying to use a package to select videos from the gallery and although the video itself plays fine, even if I set the volume to 1, 1.0, 100, etc., the audio is never heard. I even added a slider with the volume control and I didn't get any major results.

ashilkn commented 3 months ago

Facing the same issue, audio plays fine on Android.

ashilkn commented 3 months ago

@indacurdev Found a fix.

~~Using the NativeVideoPlayerController, I was first setting the volume and then playing the video. I flipped this and now audio is working.~~

  Future<void> _initializeController(
    NativeVideoPlayerController controller,
  ) async {
    _controller = controller;

    controller.onPlaybackEnded.addListener(_onPlaybackEnded);

    final videoSource = await VideoSource.init(
      path: _filePath!,
      type: VideoSourceType.file,
    );
    await controller.loadVideoSource(videoSource);
    await controller.play();
    await controller.setVolume(1);
  }

Update: Now this is also not working. Don't know why it worked for sometime after I made this change. Tested on both debug and profile mode.

ashilkn commented 3 months ago

Ah found the reason. Turn off Silent mode. The device was on Silent mode and that's why audio was muted. Video plays fine with audio on Apple Photos and that is what I was using to check if audio is working for videos on the device.

albemala commented 2 months ago

@ashilkn thank you for looking into this and finding a solution.

@indacurdev could you please check ashilkn's solution? thanks

ashilkn commented 2 months ago

I found a fix for my issue. Had to set AVAudioSession to playback on iOS for audio to work on silent mode.

Here's the code: https://github.com/ente-io/ente/pull/3037/files