Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Lỗi khi chạy video trong cửa sổ mới tạo ra - WPF C#

00:34 02-05-2017 1.340 lượt xem 1 bình luận 00:44 02-05-2017

Mình đang định làm 1 cái splash screen video. Mình cho 1 Media element vào trong mainwindow như sau:
 

<Window x:Class="splash_video.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:splash_video" Background="Transparent"
        mc:Ignorable="d" WindowStyle="None" ResizeMode="NoResize" AllowsTransparency="True"
        Title="MainWindow" Height="582.092" Width="740.958">
    <Grid Margin="10,10,10,10">
        <Grid.BitmapEffect>
            <DropShadowBitmapEffect>
                
            </DropShadowBitmapEffect>
        </Grid.BitmapEffect>
        <MediaElement Name="video" Source="C:\Users\Anh\Documents\Visual Studio 2017\Projects\splash video\splash video\0001-0200.mp4" LoadedBehavior="Play" Visibility="Visible" Stretch="UniformToFill" OpacityMask="Black">
        </MediaElement>
    </Grid>
</Window>

Tất nhiên là khi mở lên thì nó chạy tốt, vì vậy mình tạo thêm 1 cái cửa sổ làm splash screen cho cái mainwin này như sau.

Code xaml:

<Window x:Class="splash_video.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:splash_video"
        mc:Ignorable="d" 
        WindowStyle="None" ResizeMode="NoResize" AllowsTransparency="True"
        Title="window1" Height="582.092" Width="740.958">
    <Grid>
        <Grid Margin="10,10,10,10">
            <Grid.BitmapEffect>
                <DropShadowBitmapEffect>

                </DropShadowBitmapEffect>
            </Grid.BitmapEffect>
            <MediaElement Name="video" UnloadedBehavior="Manual" Source="C:\Users\Anh\Documents\Visual Studio 2017\Projects\splash video\splash video\0001-0200.mp4" LoadedBehavior="Play" Visibility="Visible" Stretch="UniformToFill" OpacityMask="Black">
            </MediaElement>
        </Grid>
    </Grid>
</Window>

Code behind App.xaml.cs:

public partial class App : Application
    {
        private const int time_splash = 6667;
        protected override void OnStartup(StartupEventArgs e)
        {
            Window1 splash = new Window1();
            splash.Show();
            Stopwatch timer = new Stopwatch();
            timer.Start();
            splash.video.Source = new Uri( @"C:\Users\Anh\Documents\Visual Studio 2017\Projects\splash video\splash video\0001 - 0200.mp4");

            base.OnStartup(e);
            MainWindow main = new MainWindow();
            timer.Stop();
            int remaining_time = time_splash - (int)timer.ElapsedMilliseconds;
            if (remaining_time > 0)
            {
                Thread.Sleep(remaining_time);
            }
            splash.Close();
        }
    }

nhưng đến đoạn này khi mở lên nó lại là 1 màn hình trắng tin 6s và chẳng có gì, video trong đó không có mặc dù trong priview nó đã hiện ra như thế này :

https://drive.google.com/open?id=0B_iJNfwmaqjVall3Ni1XOUFYelE

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 00:44 02-05-2017

1. Thử k làm cái splash gì nữa hết. Để là 1 cái media. khi bật cửa sổ lên là chạy media. Nếu ok thì do code splash bậy

2. Thử k cần timer xem nó chạy k

Câu hỏi mới nhất