Solved

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

Posted on 2010-08-24
15
626 Views
Last Modified: 2013-12-17
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++;
        }
0
Comment
Question by:thecruz
  • 7
  • 7
15 Comments
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33518733
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

0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33518751
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
0
 
LVL 6

Expert Comment

by:nipunu
ID: 33520025
0
 

Author Comment

by:thecruz
ID: 33521646
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.  
0
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
ID: 33524984
Hi,

You need to add new control in Toolbox. Right Click in ToolBox and select Choose Items. In COM Components Tab -->select Windows Media Player (wmp.dll). --> Drag and Drop the same on Window Form. Also add a button on Form name as btnPlay

And then apply code as shown in attach code.

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;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace EE_Test
{
    public partial class Form1 : Form
    {
        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();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //ProcessStartInfo startInfo = new ProcessStartInfo();
            //startInfo.FileName = "CCleaner.EXE";
            ////startInfo.Arguments = f;
            //Process.Start(startInfo);
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            // Creating PlayList
            WMPLib.IWMPPlaylist plist = axWindowsMediaPlayer1.newPlaylist("MyPlayList", "");
            DirectoryInfo di = new DirectoryInfo(@"D:\Zodes");

            foreach (FileInfo file in di.GetFiles("*", SearchOption.AllDirectories))
            {
                if (file.Extension.Equals(".bmp") || file.Extension.Equals(".jpg") ||
                    file.Extension.Equals(".mpeg") || file.Extension.Equals(".wmv") || file.Extension.Equals(".avi"))
                {
                    plist.appendItem(axWindowsMediaPlayer1.newMedia(file.FullName));
                    axWindowsMediaPlayer1.currentPlaylist = plist;              
                }
                if (axWindowsMediaPlayer1.currentPlaylist.count > 0)
                {
                    axWindowsMediaPlayer1.Ctlcontrols.playItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(0));
                }
            }
        }
    }
}

Open in new window

0
 

Author Comment

by:thecruz
ID: 33525209
thanks for the code provided but when i run it i get the following attached error.
error.JPG
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33525400
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
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Closing Comment

by:thecruz
ID: 33527670
excelent
0
 

Author Comment

by:thecruz
ID: 33527755
one las question.  Is there a way to rotate images in Windows media?
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33527783
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
0
 

Author Comment

by:thecruz
ID: 33527829
Thanks for you prompt response.
0
 

Author Comment

by:thecruz
ID: 33527904
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?
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33527989
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
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33528042
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
0
 

Author Comment

by:thecruz
ID: 33533787
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.  
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now