Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried To bind up both in Single Media Element but there some time gap between switching:


Here is what i have done till now:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Shapes;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Windows.Threading;
using System.Threading;
using System.Data;
namespace ImageVideoWPF
{
///
/// Interaction logic for ImageVideo.xaml
///

public partial class ImageVideo : Window
{

DataTable table = new DataTable();

DispatcherTimer timer = new DispatcherTimer();

int i = 0;
public static bool ContentPlaying { get; set; }

public ImageVideo()
{

InitializeComponent();



table.Columns.Add("Type", typeof(string));
table.Columns.Add("Path", typeof(string));


// Here we add five DataRows.
table.Rows.Add("Image", @"C:\Users\dell\Desktop\Awards\pic1.png");
table.Rows.Add("Image", @"C:\Users\dell\Desktop\Awards\pic2.bmp");
table.Rows.Add("Image", @"C:\Users\dell\Desktop\Awards\pic3.gif");
table.Rows.Add("Image", @"C:\Users\dell\Desktop\Awards\pic4.jpg");
table.Rows.Add("Image", @"C:\Users\dell\Desktop\IMG_4691.JPG");
table.Rows.Add("Video", @"C:\Users\dell\Desktop\Blast_Video1_LU32-43.wmv");
table.Rows.Add("Image", @"C:\Users\dell\Desktop\IMG_4693.JPG");
table.Rows.Add("Video", @"C:\Users\dell\Desktop\future_en.mp4");
table.Rows.Add("Image", @"C:\Users\dell\Desktop\IMG_4694.JPG");


}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
timer.Interval = TimeSpan.FromMilliseconds(1000);
timer.Tick += timer_Tick;
timer.Start();

}
void timer_Tick(object sender, EventArgs e)
{
MaintainPlaylist();
}

private void MaintainPlaylist()
{
if (ContentPlaying != true)
{
timer.Stop();

RunPlayList(table.Rows[i][0].ToString(), table.Rows[i][1].ToString());
i++;




}
}


private void RunPlayList( string _Type, string _Path )
{
if (_Path != null || _Path != "")
{

ContentPlaying = true;
MediaElemVideo.Source = new Uri(_Path);
MediaElemVideo.Play();

}

}

private void MediaElemVideo_MediaEnded(object sender, RoutedEventArgs e)
{
ContentPlaying = false;
timer.Start();
}
}
}



-------------------------------------------
<window x:class="ImageVideoWPF.ImageVideo" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ImageVideo" Height="300" Width="300" Loaded="Window_Loaded">
<grid>
<grid.columndefinitions>
<columndefinition> <columndefinition width="Auto"> <columndefinition width="2*">

<wrappanel name="wp" margin="5" grid.column="0">
<Button Height="20" Width="50" Name="Button1" Margin="5,5" ></Button>
<Button Height="20" Name="Button2" Width="50" Margin="5,5" ></Button>


<gridsplitter grid.column="1" width="2">
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<!--<groupbox x:name="container" grid.column="2" margin="5">-->

<grid grid.column="2" margin="5">
<!--<stackpanel name="SPImage" visibility="Collapsed">
<textblock dockpanel.dock="Top" removed="SteelBlue" height="25">Hi this is Image
<Image Name="ImageContainer"></Image>
-->

<stackpanel name="SP" visibility="Visible">
<!--<textblock dockpanel.dock="Top" removed="Green" height="25">Hi this is Video-->
<mediaelement horizontalalignment="Stretch" verticalalignment="Stretch" name="MediaElemVideo" mediaended="MediaElemVideo_MediaEnded" loadedbehavior="Manual" unloadedbehavior="Manual">






Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900