亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WPF MediaElement:視頻打開了兩次

WPF MediaElement:視頻打開了兩次

C#
繁花如伊 2022-06-12 16:33:50
我想將 MediaPlayer 用于帶有 MediaElement 的視頻和圖片。我已經做過測試,MediaElement也可以顯示圖片。目前我的問題是 MediaElement 似乎打開了兩次。這是示例代碼:XAML:<Window x:Class="TestMediaElement.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:TestMediaElement"    mc:Ignorable="d"    Title="MainWindow" Height="450" Width="800"><Grid Margin="10">    <MediaElement Name="mediaPlayer" MediaOpened="media_MediaOpened" LoadedBehavior="Play" UnloadedBehavior="Manual"/></Grid></Window>C#using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace TestMediaElement{public partial class MainWindow : Window{        int currentMediaIndex = 0;        string[] Documents;        public MainWindow()        {            InitializeComponent();            Documents = System.IO.Directory.GetFiles("C:/Users/Feller/Desktop/Test/");            Uri first = new Uri(Documents[0], UriKind.RelativeOrAbsolute);            mediaPlayer.Source = first;            mediaPlayer.MediaOpened += media_MediaOpened;               }        private void media_MediaOpened(object sender, RoutedEventArgs e)        {            Console.WriteLine("Video opened");        }    }}另一個問題是圖像會在大約 5 秒后自動關閉。誰能幫我解決這些問題?非常感謝!
查看完整描述

1 回答

?
浮云間

TA貢獻1829條經驗 獲得超4個贊

MediaOpened 事件被訂閱了兩次。從 xaml 中刪除或從代碼中刪除。

    //mediaPlayer.MediaOpened += media_MediaOpened;


查看完整回答
反對 回復 2022-06-12
  • 1 回答
  • 0 關注
  • 110 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號