Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to stop vidio playing in WebView

$
0
0

Dear experts,

I work on a Xamarin.Forms app (UWP!). It has a Master-Details architecture. The Master page has a ListView, and each item in it opens a corresponding Detail page. The first Detail page has only a WebView that plays a YouTube video upon loading. The second Detail view has just a placeholder label for now. Where I switch from first Detail page to the second, the sound of the video from the first Detail page is still heard. And when I switch back to the first Detail page, the video loads again, and now I hear two voices. How can I stop the video upon switching to the second Detail page and resume when going back? If this is not possible, how can I just stop the video upon leaving its Detail page?

Here is some code:

In MainMDPage.xaml.cs:

`
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MainMDPageMenuItem;
if (item == null)
return;

        var page = (Page)Activator.CreateInstance(item.TargetType);

        Detail = new NavigationPage(page);
        IsPresented = false;

        MasterPage.ListView.SelectedItem = null;

        PreviouslySelectedItem = item;
    }

`

In MainMDPageMaster.xaml.cs:

`
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainMDPageMaster : ContentPage
{
public ListView ListView;

    public MainMDPageMaster()
    {
        InitializeComponent();

        BindingContext = new MainMDPageMasterViewModel();
        ListView = MenuItemsListView;
    }

    class MainMDPageMasterViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<MainMDPageMenuItem> MenuItems { get; set; }

        public MainMDPageMasterViewModel()
        {
            MenuItems = new ObservableCollection<MainMDPageMenuItem>(new[]
            {
                new MainMDPageMenuItem { Id = 0, Title = "Videos", TargetType = typeof(VideoPage), IconSource = @"Assets\film-strip.jpg" },
                new MainMDPageMenuItem { Id = 1, Title = "Products", TargetType = typeof(ProductsPage), IconSource = @"Assets\products.jpg" },
            });
        }

        #region INotifyPropertyChanged Implementation
        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}`

Thanks!


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>