Link to home
Start Free TrialLog in
Avatar of thecruz
thecruz

asked on

How can i make my pictures display in sequence along with my videos?

I'm trying to create a windows form that would allow me to display my pictures and video in sequence.  Please look at the following code and let me know how i could restructure this code to do what i am trying to do:

 private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                filemax = 0;
                panel1.Controls.Clear();
                foreach (string files in Directory.GetFiles(dlg.SelectedPath))
                {
                    if (files.EndsWith(".jpg") || files.EndsWith(".jpeg") || files.EndsWith(".avi") || files.EndsWith(".mpeg"))
                    {
                        //PictureBox pb = new PictureBox();
                        //Image img = Image.FromFile(files);
                        //pb.Image = img;
                        //panel1.Controls.Add(pb);
                        listView1.Items.Add(files);
                    }
                    //else
                    //{
                    //    if (()
                    //    {
                    //        axWindowsMediaPlayer1.URL = files;
                    //    }
                    //}
                    filemax++;
                }
                timer1.Enabled = true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           
            if (filecount == filemax)
            {
                filecount = 0;
            }
            PictureBox p = (PictureBox)panel1.Controls[filecount];

            pictureBox1.Image = p.Image;

            filecount++;
        }
Avatar of Vikram Singh Saini
Vikram Singh Saini
Flag of India image

Hi,

Please check the link:
http://www.attilan.com/2008/12/crystal-image-toolkit-100-rele.php

and also have look on code. But only for slideshow of pictures.

Regards,
V.S.Saini

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ExpertsExchange
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();            
        }       

        private void fileButton_Click(System.Object sender, System.EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                foreach (string file in openFileDialog1.FileNames)
                {
                    txtBrowse.Text += file+",";
                }
                
                this.openFileDialog1_FileOk(this, null);
            }
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            pictureBox1.Image = null;
            this.Activate();
            string[] files = openFileDialog1.FileNames;

            // Open each file and display the image in pictureBox1.
            // Call Application.DoEvents to force a repaint after each
            // file is read.        
            foreach (string file in files)
            {
                if (pictureBox1.Image != null)
                {
                    // Call Sleep so the picture is briefly displayed, 
                    //which will create a slide-show effect.
                    System.Threading.Thread.Sleep(1000);
                }

                System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
                System.IO.FileStream fileStream = fileInfo.OpenRead();
                pictureBox1.Image = System.Drawing.Image.FromStream(fileStream);
                Application.DoEvents();
                fileStream.Close();                
            }            
        }    
    }
}

Open in new window

Hi,

And as concerned for video files (.avi, .mpeg) you cannot get them in pictureBox, there must be other control to do that.

Regards,
V.S.Saini
Avatar of nipunu
nipunu

Avatar of thecruz

ASKER

sorry for the lack of detail guys.  i'm using the windows media control but at the moment i'm not sure how to write the code so that the timer opens the files.  i need to be able to do a slideshow of picture but in the event that a video is found in the directory be able to play it with the windows media control.  Ones the video is done playing resume showing the pictures.  
ASKER CERTIFIED SOLUTION
Avatar of Vikram Singh Saini
Vikram Singh Saini
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thecruz

ASKER

thanks for the code provided but when i run it i get the following attached error.
error.JPG
Hi,

I tested the same all in VS 2005, VS 2010 also. It's working fine.

Check screenshot and verify if you are having both (first and last) reference in the list in your program.

And make those lines as comment which are causing problem. And test the rest of code if it is working fine or not. And try to delete all .exe files from bin folder and then execute your program fresh.

public Form1()
        {
            InitializeComponent();
            //axWindowsMediaPlayer1.StatusChange += new EventHandler(axWindowsMediaPlayer1_StatusChange);
        }

      //  void axWindowsMediaPlayer1_StatusChange(object sender, EventArgs e)       // {            // Restart playing all items in playlist           // axWindowsMediaPlayer1.Ctlcontrols.play();       // }
Regards,
V.S.Saini

See.bmp
Avatar of thecruz

ASKER

excelent
Avatar of thecruz

ASKER

one las question.  Is there a way to rotate images in Windows media?
Hi,

I have to search that code. I will reply either with code or with my result of yes or no within two hours.

Regards,
VSS
Avatar of thecruz

ASKER

Thanks for you prompt response.
Avatar of thecruz

ASKER

Please if you do not mind.  I'm adding the path to the video files to the listview control but i cant figure out how to add an image to each row or item.  here is the code i'm using:

listView1.Items.Clear();
                foreach (string files in Directory.GetFiles(dlg.SelectedPath))
                {
                    if ((files.EndsWith(".avi")) || files.EndsWith(".mpeg"))
                    {
                        listView1.Items.Add(files);
                    }
                }
How can i add an image and only list the name of the file not the whole path?
Hi,

Check link:

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/876b6517-7306-44b0-88df-caebf3b1c10f for your first question to how to add an image.

And to list the name of the file not full path use the property of FileInfo object as file.Name.

Regards,
VSS
Hi,

I searched lot on net and found that even in simply playing Window Media Player we cannot rotate our video files. So the same cannot be done in programming too because here we are just trying to control those features in our application.

There on internet they say we need to use Windows Movie Maker software to first convert it into other format means to tild in other way. However I would like to know out of curiosity the reason behind for rotating images.

I also find a nice link : http://www.codeproject.com/KB/graphics/TimeLine.aspx?msg=2879335
where Author have described about creating a nice player. If you need something advance in context of look and working you can check it.

Happy Coding!

Regards,
VSS
Avatar of thecruz

ASKER

Me and my wife take a lot of picture and unfortunately when we are viewing the pics we have to rotate them constantly.  My main reason for creating the program is because i'm tired of using the windows explorer slide show and i don't want to have to plug in my camera to the TV every time we want to see picture with their sequenced videos.