13

I m using MediaElement to play a web video. When I left the page I noticed in the Task Manager that my app was still using 10% of network and didn't drop till it finished downloading video.

I tried doing the following but no luck.

    //open link;
    mediaElement.Source = welcomeVideoURL;

    //when I leave the page OnNavigatedFrom()
    mediaElement.Stop();
    mediaElement.ClearValue(MediaElement.SourceProperty);
    mediaElement.Source = null;

Also tried to set the source to a dummy link but still no luck.

I thought that opening the Link as a Stream and use mediaElement.SetSource() could work but I haven't found anything on that...maybe I m not searching correct.

Thank you.

Romasz
  • 29,662
  • 13
  • 79
  • 154
Stamos
  • 3,938
  • 1
  • 22
  • 48
  • 1
    Have you tried without `mediaElement.AudioCategory = AudioCategory.ForegroundOnlyMedia`. And, is your server capable to handle HTTP Range? If it doesn't, there is no way to download the video in parts and it should be downloaded all at once. – kiewic Feb 28 '16 at 19:57
  • 1
    Tried it, doesnt work. Also says its deprecated. I believe the background downloader that is inside MediaElement just doesnt Dispose. But tried your HttpRandomAccessStream and worked perfectly!. – Stamos Feb 28 '16 at 20:32
  • 1
    Have a look at [`this`](http://stackoverflow.com/a/19295826/5697616). Contextually might be different but you might be able to force the stream to drop by changing the `isEnabled` to `false` then doing your standard `.Stop()` and nulling in the handler. Could also force a dispose – Gabe Mar 02 '16 at 20:58
  • Have you tried `.Close()` yet? as `.Stop()` only resets it to be played from the beginning. Try closing the stream. – Gabe Mar 03 '16 at 20:09
  • @Gabe isEnabled, Close() and Stop() or any similar doesn't exist. – Stamos Mar 03 '16 at 21:01
  • https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.mediaelement.aspx – Stamos Mar 03 '16 at 21:23

1 Answers1

1

Found this MediaElementWithHttpClient in some other question in a comment made by @kiewic. I can manage the stream and download process and easily dispose it.

 HttpRandomAccessStream videoStream = await HttpRandomAccessStream.CreateAsync(new Windows.Web.Http.HttpClient(), videoUrl);
 mediaElement.SetSource(videoStream, videoStream.ContentType);
Community
  • 1
  • 1
Stamos
  • 3,938
  • 1
  • 22
  • 48