我有一个单一的视频(时间:3秒),我需要创建2个状态
1的视频应该始终达到1.5秒,并从一开始就玩。
时间跨度TS =新的时间跨度(0,0,0,1,500);
时间跨度ts_Start =新时间跨度(0,0,0,0,0);
如果(mediaElement.position == TS)
mediaElement.position = ts_Start; //不工作这一块code
2 - 当我preSS一个按钮,该视频应该发挥的全视频(3秒)。 (简单的标志,布尔)
所以我的问题是,我怎么知道什么时候该 mediaelement.position =1.5秒
?....我想到了一个方法,比如播放或类似的东西这一点。
我解决了问题... :) :) ....
我决定让我自己的应用程序与采取其他论坛很多想法。
我的解决办法是比我的计划,我用2视频,2 mediaElements,一个mediaEnded事件和布尔变量来恰克视频....容易
和完美的作品! 解决方案是这里 ------>(解决方案,及评析)
在我的应用程序,我没有使用性能,如时钟,时间安排,DispatcherTimer,或者像CurrentTimeInvalidate任何情况下,我只是用MediaEnded事件和布尔变量。 :) 不再。我有2个视频(1.5秒和3秒)。 MediaEnded时(媒体1.5秒)mediaElement1,5sec.Position = TimeSpam.Zero;和MediElement3sec.Position = TimeSpam.Zero,当我点击该按钮,我只是评估了3秒变量(布尔)和播放COMPLET视频。
然而,源$ C $ C在这里:MainWindow.xaml
<窗口x:类=wpf_TestVideos.MainWindow
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
标题=主窗口高度=371宽度=525加载=Window_Loaded>
<电网>
< MediaElement的高度=268的HorizontalAlignment =左保证金=141,12,0,0NAME =mediaElement15secVerticalAlignment =热门WIDTH =237MediaEnded =mediaElement15sec_MediaEnded/>
< MediaElement的高度=268的HorizontalAlignment =左保证金=142,12,0,0NAME =mediaElement3secVerticalAlignment =热门WIDTH =236/>
<按钮内容=装载高度=34的HorizontalAlignment =左保证金=12,286,0,0NAME =btLoadVerticalAlignment =热门WIDTH =73点击=btLoad_Click/>
<按钮内容=INICIO JUEGO高度=23的HorizontalAlignment =左保证金=128,286,0,0NAME =btStartVerticalAlignment =热门WIDTH =86点击=btStart_Click/&GT ;
<按钮内容=&放大器; QUOT; Reconoce Gesto和放大器; QUOT;身高=23的HorizontalAlignment =左保证金=285,286,0,0NAME =btGestureVerticalAlignment =热门WIDTH =108点击=btGesture_Click/>
< /网格>
MainWindow.xaml.cs:
使用系统;
使用System.IO;
System.Collections中使用;
使用System.Collections.Generic;
使用System.Diagnostics程序;
使用System.Windows;
使用System.Windows.Forms的;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Shapes;
使用System.Windows.Controls的;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Navigation;
使用System.Linq的;
使用System.Text;
使用了System.Runtime.InteropServices;
使用System.Windows.Interop;
使用System.Windows.Media.Animation;
使用的System.Threading;
命名空间wpf_TestVideos
{
///<总结>
///为MainWindow.xaml交互逻辑
///< /总结>
公共部分类主窗口:窗口
{
公共主窗口()
{
的InitializeComponent();
}
字符串VideoLocation = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
字符串sFileName =;
字符串sFileName2 =;
布尔bVideoLoop = TRUE;
TranslateTransform反=新TranslateTransform();
私人无效btLoad_Click(对象发件人,RoutedEventArgs E)
{
mediaElement15sec.LoadedBehavior = MediaState.Manual;
mediaElement3sec.LoadedBehavior = MediaState.Manual;
btGesture.IsEnabled = TRUE;
btStart.IsEnabled = TRUE;
btLoad.IsEnabled = FALSE;
DirectoryInfo的DF =新的DirectoryInfo(VideoLocation);
如果(df.Exists)
{
sFileName = VideoLocation + @\ Krown_test_loop.mov;
mediaElement15sec.Source =新的URI(sFileName);
mediaElement15sec.Stretch = Stretch.Fill;
sFileName2 = VideoLocation + @\ Krown_test_7.mov;
mediaElement3sec.Source =新的URI(sFileName2);
mediaElement3sec.Stretch = Stretch.Fill;
}
其他
{
System.Windows.Forms.MessageBox.Show(没有本质puede cargar EL视频,TestAll);
}
}
私人无效btStart_Click(对象发件人,RoutedEventArgs E)
{
mediaElement15sec.Position = TimeSpan.Zero;
mediaElement3sec.Position = TimeSpan.Zero;
mediaElement15sec.Play();
mediaElement3sec.Play();
bVideoLoop = TRUE;
//VisualStateManager.GoToState(mediaElement15sec,Bring1,5ToFront,真正的);
}
私人无效mediaElement15sec_MediaEnded(对象发件人,RoutedEventArgs E)
{
如果(bVideoLoop)
{
mediaElement15sec.Position = TimeSpan.Zero;
mediaElement3sec.Position = TimeSpan.Zero;
}
}
私人无效btGesture_Click(对象发件人,RoutedEventArgs E)
{
bVideoLoop = FALSE;
// Animacion_Opacidad(bVideoLoop);
//VisualStateManager.GoToState(mediaElement3sec,Bring300ToFront,真正的);
}
私人无效Animacion_Opacidad(布尔BLOOP)
{
mediaElement15sec.RenderTransform =反;
如果(!BLOOP)
{
DoubleAnimation是anim1 =新DoubleAnimation是(1,0,TimeSpan.FromSeconds(1));
trans.BeginAnimation(OpacityProperty,anim1);
}
}
私人无效Window_Loaded(对象发件人,RoutedEventArgs E)
{
btGesture.IsEnabled = FALSE;
btStart.IsEnabled = FALSE;
btLoad.IsEnabled = TRUE;
}
}
}
i have a single video (duration: 3 seconds) and i need to create 2 states
1- the video should always reach the second 1.5 and play it from the start.
TimeSpan ts = new TimeSpan(0, 0, 0, 1, 500);
TimeSpan ts_Start = new TimeSpan(0, 0, 0, 0, 0);
if (mediaElement.position == ts)
mediaElement.position = ts_Start; //doesnt work this block code
2- when i press a button, the video should play the full video (3 seconds). (simple flag, boolean)
so my question is, how do i know when the mediaelement.position = 1.5 seconds
??.... i thought of a method such as playing or something like that.
i resolved the problem... :) :) ....
i decide make me own application with many ideas that had taken of other forums.
My solution was easier than i planned, i used 2 videos, 2 mediaElements, a mediaEnded event and boolean variable to chage the video....
and works perfectly! Solution are here ------> (Solution, and coments)
in my app, i didn't have to use properties like clocks, TimeLines, DispatcherTimer, or any event like a CurrentTimeInvalidate, i just used the MediaEnded event and a boolean variable. :) no more. i have 2 videos (1,5 seconds and 3 seconds). when MediaEnded(media 1,5 seconds) mediaElement1,5sec.Position = TimeSpam.Zero; and MediElement3sec.Position = TimeSpam.Zero, and when i clicked the button, i just evaluated the variable (boolean) and play complet video of 3 seconds.
however, the source code are here: MainWindow.xaml
<Window x:Class="wpf_TestVideos.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="371" Width="525" Loaded="Window_Loaded">
<Grid>
<MediaElement Height="268" HorizontalAlignment="Left" Margin="141,12,0,0" Name="mediaElement15sec" VerticalAlignment="Top" Width="237" MediaEnded="mediaElement15sec_MediaEnded" />
<MediaElement Height="268" HorizontalAlignment="Left" Margin="142,12,0,0" Name="mediaElement3sec" VerticalAlignment="Top" Width="236" />
<Button Content="Load" Height="34" HorizontalAlignment="Left" Margin="12,286,0,0" Name="btLoad" VerticalAlignment="Top" Width="73" Click="btLoad_Click" />
<Button Content="Inicio Juego" Height="23" HorizontalAlignment="Left" Margin="128,286,0,0" Name="btStart" VerticalAlignment="Top" Width="86" Click="btStart_Click" />
<Button Content=""Reconoce Gesto"" Height="23" HorizontalAlignment="Left" Margin="285,286,0,0" Name="btGesture" VerticalAlignment="Top" Width="108" Click="btGesture_Click" />
</Grid>
MainWindow.xaml.cs:
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Navigation;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows.Media.Animation;
using System.Threading;
namespace wpf_TestVideos
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
string VideoLocation = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
string sFileName = "";
string sFileName2 = "";
bool bVideoLoop = true;
TranslateTransform trans = new TranslateTransform();
private void btLoad_Click(object sender, RoutedEventArgs e)
{
mediaElement15sec.LoadedBehavior = MediaState.Manual;
mediaElement3sec.LoadedBehavior = MediaState.Manual;
btGesture.IsEnabled = true;
btStart.IsEnabled = true;
btLoad.IsEnabled = false;
DirectoryInfo df = new DirectoryInfo(VideoLocation);
if (df.Exists)
{
sFileName = VideoLocation + @"\Krown_test_loop.mov";
mediaElement15sec.Source = new Uri(sFileName);
mediaElement15sec.Stretch = Stretch.Fill;
sFileName2 = VideoLocation + @"\Krown_test_7.mov";
mediaElement3sec.Source = new Uri(sFileName2);
mediaElement3sec.Stretch = Stretch.Fill;
}
else
{
System.Windows.Forms.MessageBox.Show("No se puede cargar el video", "TestAll");
}
}
private void btStart_Click(object sender, RoutedEventArgs e)
{
mediaElement15sec.Position = TimeSpan.Zero;
mediaElement3sec.Position = TimeSpan.Zero;
mediaElement15sec.Play();
mediaElement3sec.Play();
bVideoLoop = true;
//VisualStateManager.GoToState(mediaElement15sec, "Bring1,5ToFront", true);
}
private void mediaElement15sec_MediaEnded(object sender, RoutedEventArgs e)
{
if (bVideoLoop)
{
mediaElement15sec.Position = TimeSpan.Zero;
mediaElement3sec.Position = TimeSpan.Zero;
}
}
private void btGesture_Click(object sender, RoutedEventArgs e)
{
bVideoLoop = false;
//Animacion_Opacidad(bVideoLoop);
//VisualStateManager.GoToState(mediaElement3sec, "Bring300ToFront", true);
}
private void Animacion_Opacidad(bool bLoop)
{
mediaElement15sec.RenderTransform = trans;
if (!bLoop)
{
DoubleAnimation anim1 = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(1));
trans.BeginAnimation(OpacityProperty, anim1);
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
btGesture.IsEnabled = false;
btStart.IsEnabled = false;
btLoad.IsEnabled = true;
}
}
}