视频未在我的窗口应用程序中开始

时间:2019-04-22 01:11:50

标签: c# wpf xaml

我遇到以下问题:视频未以我的窗口形式加载。我还插入了按钮来启动和播放功能,但是什么也没发生。我的模板在运行之前是看视频的,但是当窗口窗体启动时,视频的位置就没有了。

这是我的代码:


        <MediaElement Name="CheckFWmonitor" HorizontalAlignment="Left"
                      Height="200" Margin="719,107,0,0" 
                      VerticalAlignment="Top" Width="366"
                      Source="C:\crask\videos\FWMon.mp4" LoadedBehavior="Manual" />

        <StackPanel HorizontalAlignment="Left" Height="78" Margin="719,307,0,0" VerticalAlignment="Top" Width="321">
            <Label Name="lblStatus" Content="Not playing..." HorizontalContentAlignment="Center" Margin="5" />
            <WrapPanel HorizontalAlignment="Center">
                <Button Name="btnPlay" Click="BtnPlay_Click">Play</Button>
                <Button Name="btnPause" Margin="5,0" Click="BtnPause_Click">Pause</Button>
                <Button Name="btnStop" Click="BtnStop_Click">Stop</Button>
            </WrapPanel>
        </StackPanel>

这是我的CS代码:

public Notregistered()
        {
            InitializeComponent();

            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += timer_Tick;
            timer.Start();
        }

        private void Yes_Click(object sender, RoutedEventArgs e)
        {
            notregisteredsteps.yes21 yes21next = new notregisteredsteps.yes21();
            this.Hide();
            yes21next.ShowDialog();
        }
        void timer_Tick(object sender, EventArgs e)
        {
            if (CheckFWlocaly.Source != null)
            {
                if (CheckFWlocaly.NaturalDuration.HasTimeSpan)
                    lblStatus.Content = String.Format("{0} / {1}", CheckFWlocaly.Position.ToString(@"mm\:ss"), CheckFWlocaly.NaturalDuration.TimeSpan.ToString(@"mm\:ss"));
            }
            else
                lblStatus.Content = "No file selected...";
        }

        private void BtnPlay_Click(object sender, RoutedEventArgs e)
        {
            CheckFWlocaly.Play();
        }

        private void BtnPause_Click(object sender, RoutedEventArgs e)
        {
            CheckFWlocaly.Pause();
        }

        private void BtnStop_Click(object sender, RoutedEventArgs e)
        {
            CheckFWlocaly.Stop();
        }

我也遇到了与此相关的附带问题。当我尝试从项目的目录中加载文件时-如果它不是专门设置的目标,它会给我一个错误:“ System.ComponentModel.Win32Exception:'系统找不到指定的文件''”

var localTools = $@"{AppDomain.CurrentDomain.BaseDirectory}tools/facebook.rdp";
Process.Start(localTools);

,当我尝试对其进行调试时,向我显示以下位置:“ Project / Bin / Debug /(从此文件夹中搜索文件)。与将文件移至不带文件夹的目录并尝试启动它的情况相同。在那里

提前谢谢! :)

1 个答案:

答案 0 :(得分:0)

我用您的代码创建了一个项目,该项目对我来说正常工作。

  

var localTools = $ @“ {AppDomain.CurrentDomain.BaseDirectory} tools / facebook.rdp”;

在文件路径中使用\代替/;