Solved

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

Posted on 2010-08-24
15
632 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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