Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 668
  • Last Modified:

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++;
        }
0
thecruz
Asked:
thecruz
  • 7
  • 7
1 Solution
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
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
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
thecruzAuthor Commented:
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
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
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
 
thecruzAuthor Commented:
thanks for the code provided but when i run it i get the following attached error.
error.JPG
0
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
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
 
thecruzAuthor Commented:
excelent
0
 
thecruzAuthor Commented:
one las question.  Is there a way to rotate images in Windows media?
0
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
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
 
thecruzAuthor Commented:
Thanks for you prompt response.
0
 
thecruzAuthor Commented:
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
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
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
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
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
 
thecruzAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now