The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
MediaPlayerElement Crash Application RRS feed

  • Question

  • I am using MediaPlayerElement for playing Video...

    After Video Play or In between when video is playing..when i am trying to dispose that usercontrol.. gettting error or some time application crash

    Error:- Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

       at Windows.UI.Xaml.Controls.MediaPlayerElement.put_Source(IMediaPlaybackSource value)
       at MangoAppsUWP.Controls.View.ChatMessages.UC_ListItem_ChatVideo.Dispose()
       at MangoAppsUWP.ViewModels.LandingUserControl.ChatPanel.ChatScreenViewModel.Dispose()

    Question:- How to propery dispose media player element.. when its state is player/stop any time..

    MediaPlayerElement videoAttachment;
            public UC_ListItem_ChatVideo()
            {
                this.InitializeComponent();
                Loaded += UC_ListItem_ChatVideo_Loaded;
                Unloaded += UC_ListItem_Unloaded;
                ViewModel.PlayMedia += ViewModel_PlayMedia;
     
            }
     
            private void ViewModel_PlayMedia(string path)
            {
                videoAttachment.Source = MediaSource.CreateFromUri(new Uri(path));
            }
     
            private void UC_ListItem_ChatVideo_Loaded(object senderRoutedEventArgs e)
            {
                videoAttachment = new MediaPlayerElement();
                videoAttachment.AreTransportControlsEnabled = true;
                videoAttachment.AutoPlay = true;
                videoAttachment.HorizontalAlignment = HorizontalAlignment.Left;
                videoAttachment.HorizontalAlignment = HorizontalAlignment.Left;
                videoAttachment.MediaPlayer.MediaEnded += MediaPlayer_MediaEndedAsync;
                videoAttachment.Width = 520;
                videoAttachment.Height = 320;
                
                gridMedia.Children.Add(videoAttachment);
            }
     
            private async void MediaPlayer_MediaEndedAsync(Windows.Media.Playback.MediaPlayer senderobject args)
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                {
                    videoAttachment.Visibility = Visibility.Collapsed;
                });
     
            }
     
            public void Dispose()
            {
                videoAttachment.MediaPlayer.MediaEnded -= MediaPlayer_MediaEndedAsync;
                ViewModel.PlayMedia -= ViewModel_PlayMedia;
                
                videoAttachment.MediaPlayer.Pause();
                videoAttachment.MediaPlayer.Dispose();
                
                videoAttachment.IsEnabled = false;
                videoAttachment.Source = null;
                gridMedia.Children.Remove(videoAttachment);
                gridMedia.Children.Clear();
                ViewModel.Dispose();
            }

    Wednesday, June 26, 2019 6:23 AM

All replies

  • Hi,

    I noticed that you had disposed the MediaPlayElement.MediaPlayer and moved the MediaPlayElement from the grid. What about set videoAttachment=null? As the MediaPlayElement has been assigned to the videoAttachment, it will also keep a reference for the MediaPlayElement.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 27, 2019 5:51 AM
    Moderator