13 Replies - 894 Views - Last Post: 24 November 2010 - 08:41 AM Rate Topic: -----

#1 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

using File Dialog

Posted 24 November 2010 - 04:47 AM

Hi i am try to make an mp3 player i am using the windows media control. I am try to open a file directory where i have stored a song

i can get the song to play but when i click the link on my gui called rap it opens up the file directory and ask me to seleted the file i want to play but i would like it to know what file i want to play say 2Pac from the file directory

how can i change my code to suit this:

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


namespace musicChoice
{
    public partial class frmMusicPlayer : Form
    {
        
        public frmMusicPlayer()
        {
            InitializeComponent();
        }
        private void frmMusicPlayer_Load(object sender, EventArgs e)
        {

        }
        private void btnPause_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }

        private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            // Diectory of the music i want to play
            dlg.InitialDirectory = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice 2pac";
            dlg.CheckFileExists = true;
            dlg.Multiselect = false;
            dlg.Filter = "Media Files(*.avi;*.mp3;*.mpg;*.mpa)" +
                   "|*.avi;*.mp3;*.mpg;*.mpa|" +
                   "All files (*.*)|*.*";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = dlg.FileName;
            }
        }
    }
}


Is This A Good Question/Topic? 0
  • +

Replies To: using File Dialog

#2 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: using File Dialog

Posted 24 November 2010 - 04:56 AM

I am not completely understanding your question. What error are you getting?

Two things that you can try:
1. check that the path is right. some of those folder names are down right impressive!
2. change the dlg.Filter to be :
dlg.Filter = "Media Files(*.avi;*.mp3;*.mpg;*.mpa)|*.avi;*.mp3;*.mpg;*.mpa|All files (*.*)|*.*";

although I am not sure that will make a difference.
Was This Post Helpful? 0
  • +
  • -

#3 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: using File Dialog

Posted 24 November 2010 - 05:32 AM

No the folder is fine and it does play i just don't want to have to open the file location and select the file that i want to play every time i click the link

i want to be able to hard code the file path in so when i click the link it will automaticaly play the file.
Was This Post Helpful? 0
  • +
  • -

#4 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: using File Dialog

Posted 24 November 2010 - 05:37 AM

dlg.FileName;
is nothing more than a string. Hard code it if you want. I would say it would look better to go with some sort of settings file (XML being my favorite) and just read the path and file name from there.

axWindowsMediaPlayer1.URL = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice 2pac\California Love.mp3";
should do the trick, however I like Hail Mary better :P
Was This Post Helpful? 0
  • +
  • -

#5 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: using File Dialog

Posted 24 November 2010 - 05:42 AM

View PostAdkins, on 24 November 2010 - 04:37 AM, said:

dlg.FileName;
is nothing more than a string. Hard code it if you want. I would say it would look better to go with some sort of settings file (XML being my favorite) and just read the path and file name from there.

axWindowsMediaPlayer1.URL = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice 2pac\California Love.mp3";
should do the trick, however I like Hail Mary better :P

lol cheers mate please explain xml a bit more so i know what it is then i might try to use it
Was This Post Helpful? 0
  • +
  • -

#6 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: using File Dialog

Posted 24 November 2010 - 05:50 AM

What is XML?

If you want to see how to parse XML check my SharpDIC application in my signature, I used a very simple intuitive way.

I would recommend against using XML for this though. Just use the App.config file and the built in ConfigurationManager class.
Was This Post Helpful? 0
  • +
  • -

#7 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: using File Dialog

Posted 24 November 2010 - 05:57 AM

XML is simply an option for storing data that can later be parsed. It is quite expansive and if you aren't familiar with it, it would take a bit more explaining than I think would be appropriate here. If you click this link, it will send you to a great site for learning all about the XML file format, and then this link will let you see how to use that info with C#. Also simply using the project Settings in VS will do the trick.

FYI: The first link goes to W3Schools and the second one to the main Linq to XML page on MSDN

@Sergio: That is true, I am just a sucker for specially made XML settings files that only do exactly what you want. The come in handy once your initial program expands beyond your initial expectations.
Was This Post Helpful? 0
  • +
  • -

#8 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: using File Dialog

Posted 24 November 2010 - 06:26 AM

I tried changing it to a string like you said to ard code it in but it still send me to the file location to select the file

i think this is my problem here
            dlg.InitialDirectory = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice 2pac";





here is my code could you please give a bit more advice:

        private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            // Diectory of the music i want to play
            dlg.InitialDirectory = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice 2pac";
            dlg.CheckFileExists = true;
            dlg.Multiselect = false;
            dlg.Filter = "Media Files(*.avi;*.mp3;*.mpg;*.mpa)" +
                   "|*.avi;*.mp3;*.mpg;*.mpa|" +
                   "All files (*.*)|*.*";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice 2pac";
            }

Was This Post Helpful? 0
  • +
  • -

#9 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: using File Dialog

Posted 24 November 2010 - 06:41 AM

private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
     axWindowsMediaPlayer1.URL = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice 2pac";
}



You are simply trying to hard. If you don't want it to ask where the file comes from, then don't tell it to ask :P
Was This Post Helpful? 0
  • +
  • -

#10 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: using File Dialog

Posted 24 November 2010 - 06:52 AM

View PostAdkins, on 24 November 2010 - 05:41 AM, said:

private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
     axWindowsMediaPlayer1.URL = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice 2pac";
}



You are simply trying to hard. If you don't want it to ask where the file comes from, then don't tell it to ask :P

I just change it there i got it to work the way i want but i had to add .mp3 at the end is that the tell media player what file formatt it is play just wondering lol

axWindowsMediaPlayer1.URL = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice\2pac.mp3";

Was This Post Helpful? 0
  • +
  • -

#11 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: using File Dialog

Posted 24 November 2010 - 07:04 AM

no, you need the .mp3 at the end so it knows what file to grab. The name of the file is "2pac.mp3" so you have to tell it that explicitly.
Was This Post Helpful? 1
  • +
  • -

#12 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: using File Dialog

Posted 24 November 2010 - 08:26 AM

Hi just a small problem when i am playing a file and click pause the song will pause no problem but when i click the play button to unpause the song the play button does nothing i am getting no errors can't find out what i am doing wrong some help please.

My code:

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


namespace musicChoice
{
    public partial class frmMusicPlayer : Form
    {
        
        public frmMusicPlayer()
        {
            InitializeComponent();
        }
        private void btnPlay_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }
        private void btnPause_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }
        private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            BackColor = Color.Black; // If button Stop click set form colour to Red
            pb2Pac.Show();
            axWindowsMediaPlayer1.URL = @"F:\Uni work\Com321 derek Week2 programing ex\LastCodeProjectc#\musicChoice\2pac.mp3";
        }

        private void btnFastForward_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.fastForward();

        }

        private void btnRewind_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.fastReverse();
        }
    }
}

Was This Post Helpful? 0
  • +
  • -

#13 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: using File Dialog

Posted 24 November 2010 - 08:37 AM

no promises but try this out:
if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsStopped)
{
     axWindowsMediaPlayer1.Ctlcontrols.play();
}


Was This Post Helpful? 0
  • +
  • -

#14 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: using File Dialog

Posted 24 November 2010 - 08:41 AM

Sorry Adkins i named it wrong sorry for wasting your time :stupid:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1