0

我想在我的应用中播放视频。我环顾四周,但没有任何帮助。我问用户是否想听他的手机音乐。如果单击确定,则音乐继续播放,否则音乐停止。从现在开始没问题。现在,我的问题是:我创建了一个网格来使用它,例如具有宽度和高度等的弹出窗口。当这个弹出窗口出现时,音乐停止。这就是为什么无法在市场上认证我的应用程序的原因。这是一个小代码:我相信很容易理解......请帮助!

public void new_grid(int v)
        {
            Grid gr = new Grid();
            gr.Background = new SolidColorBrush(Colors.Cyan);
            gr.Opacity = 1.0;
            gr.Width = 400;
            gr.Height = 600;
            // Create a white border.
            Border border = new Border();
            border.BorderBrush = new SolidColorBrush(Colors.White);
            border.BorderThickness = new Thickness(7.0);

            MediaElement video_ship = new MediaElement();
            //video_ship.AutoPlay = false;

            video_ship.Width = 400;
            video_ship.Height = 600;
            video_ship.VerticalAlignment = VerticalAlignment.Top;
            video_ship.HorizontalAlignment = HorizontalAlignment.Left;
            if (v == 1)
            {
                video_ship.Source = new Uri("videos/Lost_Ship.wmv", UriKind.RelativeOrAbsolute);
                //video_ship.Play();
                gr.Children.Add(video_ship);
            }
            else if (v == 2)
            {
                //video_ship.Source = "videos/Lost_Ship.wmv";
                video_ship.Source = new Uri("videos/you_are_on_fire.wmv", UriKind.RelativeOrAbsolute);
                //video_ship.Name = "fire";
                //video_ship.Play();
                gr.Children.Add(video_ship);
            }
            else if (v == 3)
            {
                //video_ship.SourceName = "videos/Lost_Ship.wmv";
                video_ship.Source = new Uri("videos/EscapeShip.wmv", UriKind.RelativeOrAbsolute);
                //video_ship.Name = "escape";
                //video_ship.Play();
                gr.Children.Add(video_ship);
            }

我发送一个变量 v 来选择我的一个视频..我将视频设置为构建动作内容

有什么想法该怎么做?或与此不同的东西?我只想播放视频..视频没有音乐..或音效..

4

1 回答 1

0

我测试了它并且它有效。您想在调用事件时弹出视频。所以你应该把网格放在文件 xaml 代码中,它是隐藏的。这是我的测试

在 xml 上

<Grid x:Name="LayoutRoot" Background="Transparent">  
        <Image Source="BackgroundMain3.jpg" Stretch="UniformToFill"/>
        <Grid Height="400" Width="600" x:Name="playvideo" Visibility="Collapsed">
            <MediaElement x:Name="element"/>
        </Grid>
        <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="129,684,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
</Grid>

在 xaml.cs 上

private void button1_Click(object sender, RoutedEventArgs e)
        {
            poupup(3);
            playvideo.Visibility = Visibility.Visible;
            playvideo.Opacity = 0.8;
            element.MediaOpened += new RoutedEventHandler(element_MediaOpened);
        }

        void element_MediaOpened(object sender, RoutedEventArgs e)
        {
            element.Play();
        }

        public void poupup(int v)
        {
            if (v == 1)
            {
                element.Source = new Uri("videos/Lost_Ship.wmv", UriKind.RelativeOrAbsolute);
            }
            else if (v == 2)
            {

                element.Source = new Uri("videos/you_are_on_fire.wmv", UriKind.RelativeOrAbsolute);

            }
            else if (v == 3)
            {
                element.Source = new Uri("YouTube.mp4", UriKind.RelativeOrAbsolute);

            }

        }
于 2012-04-17T16:58:05.880 回答