MediaElement spielt Video nicht ab
Hallo liebe Windows Phone Freunde,
ich wollte mich heute mal an einer Media-App probieren und habe
dabei das Problem, dass ein Video nicht abgespielt wird.
Ich lasse mir den State auf einer TextBox ausgeben und wenn
ich das Video starte steht "Opening" und direkt danach (ohne
das das Video abgespielt wurde) "Closed".
Ich nutze folgenden Code:
Code:
<phone:PhoneApplicationPage
x:Class="SimpleVideoPlayer.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot ist das Stammraster, in dem alle anderen Seiteninhalte platziert werden-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel enthält den Namen der Anwendung und den Seitentitel-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Simple Video-Player" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Video-Player" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - zusätzliche Inhalte hier platzieren-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<MediaElement Height="334" HorizontalAlignment="Left" Name="mediaElement1" VerticalAlignment="Top" Width="456" Source="/Media/Video/Wildlife.wmv" AutoPlay="True" CurrentStateChanged="mediaElement1_CurrentStateChanged" />
<TextBlock Height="61" HorizontalAlignment="Left" Margin="9,372,0,0" Name="stateBlock" Text="State:" VerticalAlignment="Top" Width="218" TextAlignment="Center" FontSize="35" />
<TextBox Height="73" HorizontalAlignment="Left" Margin="235,360,0,0" Name="stateBox" Text="" VerticalAlignment="Top" Width="218" IsReadOnly="True" />
<Slider Height="84" HorizontalAlignment="Left" Margin="0,425,0,0" Name="volumeSlider" VerticalAlignment="Top" Width="456" Maximum="20" Value="15" SmallChange="1" ValueChanged="volumeSlider_ValueChanged" />
<Button Content="Play" Height="72" HorizontalAlignment="Left" Margin="6,502,0,0" Name="play" VerticalAlignment="Top" Width="160" Click="play_Click" />
<Button Content="Pause" Height="72" HorizontalAlignment="Left" Margin="290,502,0,0" Name="pause" VerticalAlignment="Top" Width="160" Click="pause_Click" />
<Button Content="Stopp" Height="72" HorizontalAlignment="Left" Margin="149,502,0,0" Name="stopp" VerticalAlignment="Top" Width="160" Click="stopp_Click" />
</Grid>
</Grid>
<!--Beispielcode für die Verwendung von ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Schaltfläche 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Schaltfläche 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Menüelement 1"/>
<shell:ApplicationBarMenuItem Text="Menüelement 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->
</phone:PhoneApplicationPage>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace SimpleVideoPlayer
{
public partial class MainPage : PhoneApplicationPage
{
// Konstruktor
public MainPage()
{
InitializeComponent();
}
private void play_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Play();
}
private void stopp_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Stop();
}
private void pause_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Pause();
}
private void mediaElement1_CurrentStateChanged(Object sender, RoutedEventArgs e)
{
stateBox.Text = mediaElement1.CurrentState.ToString();
}
private void volumeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (mediaElement1 != null)
{
mediaElement1.Volume = volumeSlider.Value * 0.05;
}
}
}
}
Kann mir jemand sagen was ich falsch mache? :)
AW: MediaElement spielt Video nicht ab
Hat sich erledigt:
.wmv ist nicht .wmv auch da gibt es unterschiede. Again what learned ;)