RE: Events dont fire
From: Anders Keis Hansen (akha99_at_online.nospam)
Date: 11/30/04
- Next message: Mark Ingram: "Re: Warning for DirectShow developers with Nero Burning ROM 6.6 instal"
- Previous message: Cairn: "Selecting correct Codec Filter"
- In reply to: Rhett Gong [MSFT]: "RE: Events dont fire"
- Next in thread: Rhett Gong [MSFT]: "RE: Events dont fire"
- Reply: Rhett Gong [MSFT]: "RE: Events dont fire"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 30 Nov 2004 03:23:04 -0800
Hi Rhett
you have to have a folder called c:\myfiles which contain an video clip with
sound
Else the code is here, i put in a comment i my problem area with the sound
in english. Here is the code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.AudioVideoPlayback;
using Microsoft.DirectX.DirectDraw;
using System.IO;
namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private string[] m_playlist = null;
private int maxindex = 0;
private int videoindex = 0;
private Video video;
private string videoPath = "C:\\myfiles";
private Timer mytimer;
private string mytest = "";
private string mainPath = "C:\\myfiles";
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
m_playlist = FillPlaylist();
PlayVideo();
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
//
// Form1
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Desktop;
this.ClientSize = new System.Drawing.Size(1016, 720);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition =
System.Windows.Forms.FormStartPosition.WindowsDefaultBounds;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private string[] FillPlaylist()
{
// Sæt maxindex til antal videoer i path
maxindex = Directory.GetFiles(videoPath).Length;
if (maxindex <= 0)
{
MessageBox.Show("Der er ikke lagt billeder eller film ind i c:\\myfiles
kataloget, Dynamiks player lukkes ned");
}
// Lav playlisten
string[] playlist = new string[maxindex];
// udfyld playliste
playlist = Directory.GetFiles(videoPath);
// Returner string array
return playlist;
}
private void PlayVideo()
{
mytimer = new Timer();
try
{
mytest = m_playlist[0].Substring(m_playlist[0].Length-3,3);
if (mytest.ToLower() == "jpg")
{
mytimer.Interval = 10000;
mytimer.Enabled = true;
video = new Video(m_playlist[0]);//
video.Owner = this;
video.Size = new Size(1024,768);
video.HideCursor();
video.Play();
mytimer.Tick += new System.EventHandler (this.OnVideoEnding);
}
else
{
video = new Video(m_playlist[0]);
video.Ending += new EventHandler(this.OnVideoEnding);
video.Owner = this;
video.Size = new Size(1024,768);
video.HideCursor();
video.Play();
//If commented out, events fire on video.Edning
video.Audio.Volume = 0;
}
}
catch(Exception)
{
}
}
private void OnVideoEnding(object sender, System.EventArgs e)
{
mytimer.Stop();
// Check om Video kører
if(video != null)
{
// Forøg musikindex
videoindex++;
// Stop nuværende
//video.Stop();
if(videoindex >= maxindex)
{
videoindex = 0;
}
try
{
mytest = m_playlist[videoindex].Substring(m_playlist[videoindex].Length-3,3);
if (mytest.ToLower() == "jpg")
{
mytimer = new Timer();
mytimer.Interval = 10000;
mytimer.Enabled = true; // åbn næste video i array
video.Open(m_playlist[videoindex]);
// Reset Ending event
mytimer.Tick -= new EventHandler(this.OnVideoEnding);
mytimer.Tick += new EventHandler(this.OnVideoEnding);
// afspil
video.Owner = this;
video.Size = new Size(1024, 768);
video.HideCursor();
video.Play();
}
else
{
video.Open(m_playlist[videoindex]);
// Reset
video.Ending -= new EventHandler(this.OnVideoEnding);
video.Ending += new EventHandler(this.OnVideoEnding);
// afspil
video.Owner = this;
video.Size = new Size(1024, 768);
video.HideCursor();
video.Play();
}
}
catch(Exception)
{
// If they are any problems, exit the application
MessageBox.Show("Der lagt materiale ind som ikke understøttes af
afspilleren, *.avi,*.mpg,*.jpg,*.vob er gyldige formater, afspiller lukkes,
fjern venligst ugyldigt materiale fra myfiles kataloget");
}
}
}
}
}
- Next message: Mark Ingram: "Re: Warning for DirectShow developers with Nero Burning ROM 6.6 instal"
- Previous message: Cairn: "Selecting correct Codec Filter"
- In reply to: Rhett Gong [MSFT]: "RE: Events dont fire"
- Next in thread: Rhett Gong [MSFT]: "RE: Events dont fire"
- Reply: Rhett Gong [MSFT]: "RE: Events dont fire"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|