Windows Phone 8.1 MediaElement Crash (exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

I had a very strange problem that I can’t wrap my head in.

I created a very simple WP 8.1 application to show the problem:

MainPage.xaml:

<Page x:Class="App6.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App6" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid> <MediaElement x:Name="MediaElement1" Source="/Assets/Audio/clap_01.mp3" Visibility="Collapsed" AutoPlay="False" /> <MediaElement x:Name="MediaElement2" Source="/Assets/Audio/click_01.mp3" Visibility="Collapsed" AutoPlay="False" /> <MediaElement x:Name="MediaElement3" Source="/Assets/Audio/cowbell_01.mp3" Visibility="Collapsed" AutoPlay="False" /> <MediaElement x:Name="MediaElement4" Source="/Assets/Audio/kick_01.mp3" Visibility="Collapsed" AutoPlay="False" /> <Button Content="Button" HorizontalAlignment="Left" Margin="125,118,0,0" VerticalAlignment="Top" Height="147" Width="150" Click="ButtonBase_OnClick" /> </Grid> </Page> 

MainPage.xaml.cs:

 namespace App6 { public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; } protected override void OnNavigatedTo(NavigationEventArgs e) { } private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { MediaElement1.Play(); } } } 

Now, if I press the button (especially right after turning on the application), I get a "Crash (exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)") in MediaElement1.Play (); line. It is truly strange that an exception only appears if there are 4 or more MediaElements, and if there are 1,2,3, it works fine. I tried to find a solution to this problem for the whole day, and I would be very grateful for any help.

+6
source share
1 answer

As you want to play several sounds at once, MediaElement will not work for you, unfortunately. You probably need to use the XNA SoundEffect Class.

0
source

Source: https://habr.com/ru/post/970002/


All Articles