We are currently playing a 4K h.265 video in an UWP app as background using MediaPlayerElement. We have set the MediaPlayer to infinite loop using IsLoopingEnabled = true
. The problem is, that the memory usage is increasing every time the video loops. If we disable looping, the memory leak does not occure. We tried looping the video manually by resetting the position to zero when the video finished, but still it leaks memory. We also tried to call System.GC.collect() but that also did nothing.
Is this a UWP bug or are we missing something?
Edit:
Here is the code we are using:
MainPage.xaml
<Page
x:Class="MyProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:MyApp.Controls"
xmlns:xaml="using:Microsoft.Graphics.Canvas.UI.Xaml"
mc:Ignorable="d"
Background="Black" Loaded="MainPage_OnLoaded" Unloaded="MainPage_OnUnloaded">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{StaticResource AppBrushNewBlue1}">
<MediaPlayerElement Name="bgMovie" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AreTransportControlsEnabled="False" ></MediaPlayerElement>
<Canvas Name="mainCanvas" ManipulationMode="None" Background="Transparent">
</Canvas>
</Grid>
MainPage.xaml.cs
private MediaSource ms;
private async void MainPage_OnLoaded(object sender, RoutedEventArgs e)
{
ms = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/bg_animation_V2.mp4"));
bgMovie.Source = ms;
bgMovie.MediaPlayer.IsLoopingEnabled = true;
bgMovie.MediaPlayer.Play();
[...]
}
We are not doing anything more with the MediaSource or the mediaPlayer itself. When we disable IsLoopingEnabled
no memory leak occurs anymore.