I've been trying to get my mp3 player app to automatically play a new mp3 after it's finished his current one. However it doesn't work how I planned.
First here is my code:
using System;
using System.Windows.Forms;
namespace TestMp3
{
public partial class Form1 : Form
{
private WMPLib.WindowsMediaPlayer wmp;
public Form1()
{
InitializeComponent();
wmp = new WMPLib.WindowsMediaPlayer();
wmp.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(PlayStateChange);
wmp.MediaError += new WMPLib._WMPOCXEvents_MediaErrorEventHandler(MediaError);
}
private void Play(string path)
{
wmp.controls.stop();
wmp.close();
wmp.URL = path;
wmp.controls.play();
}
private void Next(string path)
{
button1.Enabled = false;
Play(@"C:\xml\music\songs\bird.mp3");
}
private void PlayStateChange(int NewState)
{
if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
{
Next("");
}
}
private void MediaError(object pMediaObject)
{
button1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
Play(@"C:\xml\music\songs\bee.mp3");
}
}
}
And here is what it does and what it doesn't do:
- Start playing bee.mp3
- Run the code in the play state changed (Next())
- Disable the button and run Play method with bird.mp3
- It runs all the code in the Play method
- Goes to play state changed again (I have no idea why but it stops from playing) It doesn't play the second song.
- Starts again the next method thus calling Play again on birds.mp3
- Runs all the code in Play method
- End of Line, nothing happens from here, Nothing is singing, nothing is happening anymore, no code is being executed it just goes idle.
Any idea?
Thank You,
IAmCypher
Edit: I forgot to add that I've read this thread and I couldn't find my answer.
This post has been edited by IAmCypher: 25 November 2010 - 01:32 PM

New Topic/Question
Reply




MultiQuote






|