首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >简单的MediaElement类示例

简单的MediaElement类示例
EN

Stack Overflow用户
提问于 2012-12-05 03:06:15
回答 1查看 851关注 0票数 0

我试着学习MediaElement Class..所以我找到了一个例子,但当我运行它不工作(视频不播放)…有人能告诉我为什么吗?

屏幕:

XAML:

代码语言:javascript
复制
<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>

政务司司长:

代码语言:javascript
复制
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建议后添加了两个事件...

代码语言:javascript
复制
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,我该怎么办?

EN

回答 1

Stack Overflow用户

发布于 2012-12-05 05:11:45

您是否将wmv文件的构建操作设置为Content而不是Resource?如果是,请尝试连接到MediaElement的MediaOpened和MediaFailed事件,查看文件是否已加载或失败(并查看预期以确定原因)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13710111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档