Baseflow / XamarinMediaManager

Cross platform Xamarin plugin to play and control Audio and Video
https://baseflow.com
MIT License
769 stars 306 forks source link

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

Open pzimmermaninmo opened 5 years ago

pzimmermaninmo commented 5 years ago

🐛 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:

barrysohl commented 4 years ago

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.

LittleBoxOfChicken commented 3 years ago

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 commented 3 years ago

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

LittleBoxOfChicken commented 3 years ago

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;
    }
}
tompi commented 3 years ago

Thnx a lot @LittleBoxOfChicken

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

IngJorgeCruz commented 3 years ago

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(); }

theakkadian commented 3 years ago

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); }