私はMediaElementクラスを学ぼうとしています..だから私は1つの例を見つけましたが、実行すると機能しません(ビデオが再生されません)...誰かが理由を教えてもらえますか?
画面:
XAML:
<phone:PhoneApplicationPage
x:Class="Player.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">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="339"/>
<RowDefinition Height="429*"/>
</Grid.RowDefinitions>
<MediaElement Height="238" HorizontalAlignment="Left" Margin="12,12,0,0"
Name="mediaElement1" VerticalAlignment="Top" Width="424"
Source="/video/Wildlife.wmv" AutoPlay="True" />
<Button Content="Play" Height="81" HorizontalAlignment="Left" Margin="12,258,0,0"
Name="PlayButton" VerticalAlignment="Top" Width="134" Click="PlayButton_Click" />
<Button Content="Pause" Height="81" HorizontalAlignment="Left" Margin="152,258,0,0"
Name="PauseButton" VerticalAlignment="Top" Width="124" Click="PauseButton_Click" />
<Button Content="Stop" Height="81" HorizontalAlignment="Right" Margin="0,258,65,0"
Name="StopButton" VerticalAlignment="Top" Width="133" Click="StopButton_Click" />
</Grid>
CS:
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 Player
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void PlayButton_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Play();
}
private void PauseButton_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Pause();
}
private void StopButton_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Stop();
}
}
}
編集: @Igor Kulman の提案の後に 2 つのイベントを追加しました...
private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
{
MessageBox.Show("Opened");
}
private void mediaElement1_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
MessageBox.Show("Failed");
}
そして、3〜5秒の遅延後にメッセージボックスが返されFailed
ました。