XamarinMediaManager icon indicating copy to clipboard operation
XamarinMediaManager copied to clipboard

Xamarin Forms - Video cannot be played when AutoPlay is set to false on iOS

Open retepz opened this issue 6 years ago • 7 comments

🐛 Bug Report

Using the VideoView in Xamarin forms, if you set autoplay to false, the video will stay black and never play. Tapping play does nothing at all. I've seen this with two urls so far.

Expected behavior

Video should play when play is pressed or Play() method is called

Reproduction steps

Here is my code to reproduce

public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); var videoPlayer = new VideoView(); videoPlayer.Source = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; videoPlayer.VerticalOptions = LayoutOptions.Center; videoPlayer.HorizontalOptions = LayoutOptions.Center; videoPlayer.WidthRequest = 200; videoPlayer.HeightRequest = 200; videoPlayer.ShowControls = true; videoPlayer.AutoPlay = false; Content = videoPlayer; } }

Configuration

Version: v0.8.18 iOS 12.4 iPhone 6s Xamarin Forms 4.3 Plugin.MediaManager: v0.8.18 Plugin.MediaManager.Forms: v0.8.18

Platform:

  • [x] :iphone: iOS
  • [ ] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [x] :monkey: Xamarin.Forms

retepz avatar Nov 10 '19 01:11 retepz

Any update on this? I have the same issue. 100% of the time on all URLs on iOS. If AutoPlay is false, then manually calling Play (or any other player command) has no effect, the video will not start. However, with AutoPlay true, then all calls afterward behave as expected.

barrysohl avatar Jul 01 '20 16:07 barrysohl

Feel like I'm responding to all the issues in this repo.

Yes I'm also having the same issue on iOS. The controls will not appear when autoplay is set to false.

LittleBoxOfChicken avatar Feb 22 '21 15:02 LittleBoxOfChicken

Also, did you ever solve this @barrysohl? What did you try?

LittleBoxOfChicken avatar Feb 22 '21 15:02 LittleBoxOfChicken

Alright, coming back to this.

I found a workaround that works for me but it also feels incredibly unstable and I hate myself for writing it.

videoView.AutoPlay = true;
CrossMediaManager.Current.StateChanged += StopAudioImmediatelyOniOS;
private async void StopAudioImmediatelyOniOS(object sender, StateChangedEventArgs e)
{
    if (e.State != MediaPlayerState.Stopped && e.State != MediaPlayerState.Paused)
    {
        await CrossMediaManager.Current.Pause();
        CrossMediaManager.Current.StateChanged -= StopAudioImmediatelyOniOS;
    }
}

LittleBoxOfChicken avatar Feb 22 '21 16:02 LittleBoxOfChicken

Thnx a lot @LittleBoxOfChicken

You deserve a BIG box of chicken for this workaround, methinks ;-)

tompi avatar Apr 08 '21 06:04 tompi

Hola, les comparto una solución:

if (Device.RuntimePlatform == Device.iOS) { CrossMediaManager.Current.BufferedChanged += Current_BufferedChanged; CrossMediaManager.Current.MediaItemFinished += Current_MediaItemFinished; }

private void Current_MediaItemFinished(object sender, MediaManager.Media.MediaItemEventArgs e) { CrossMediaManager.Current.Stop(); CrossMediaManager.Current.Dispose(); Video = new MediaManager.Forms.VideoView { IsFullWindow = true, AutoPlay = true, ShowControls = true, HeightRequest = 200, Source = vm.Datos.Video.UrlArchivo }; }

private void Current_BufferedChanged(object sender, MediaManager.Playback.BufferedChangedEventArgs e) { CrossMediaManager.Current.Pause(); }

IngJorgeCruz avatar Jul 06 '21 01:07 IngJorgeCruz

So for me, the CrossMediaManage.Current.Play(x); was only working well in Android, but on iOS, it was playing the audio, with a black screen. So the only way I had it work, is somehow refresh the page (maybe is forcing the onAppearing to happen), so please don't laugh, but this worked for me:

if (Device.RunTimePlatform == Device.iOS && shouldPlayVideo) { await Navigation.PushModalAsync(new Page(), false); await Navigation.PopModalAsync(false); }

theakkadian avatar Jul 31 '21 03:07 theakkadian