Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to create a small windows application, which is playing mpe files one by one continuously. I can add many mp3 files and play one by one by clicking each files. But actually I want automatically it should jump into next song.


So can any one help me?


Thanks in @dv@nce......:P
Posted
Updated 5-Feb-20 20:50pm
Comments
Nelek 25-Jun-13 5:57am    
Yes, there are a lot of very capable people here in CP who can help you. But you didn't describe any problem. Please read What have you tried?[^] so you can understand what I am telling
MuhammadUSman1 25-Jun-13 6:19am    
You can do it easily but as Nelek said What have you tried? so for
Aboobakkar Siddeq D U 25-Jun-13 6:36am    
Yeah I tried many times. Still i'm trying that one. But i'm not getting anything about that. Actually I want to play song continuously one by one, without stop, without pressing any button or any files. So can you help me?
Aboobakkar Siddeq D U 25-Jun-13 6:37am    
THIS IS MY CODE HERE I CAN PLAY SONG DIRECTLY BUT IT WILL PLAY ONLY ONE SONG AND STOP THERE I WANT TO PLAY 2ND SONG WITHOUT PRESSING ANY BUTTON OR FILES


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.IO;

namespace Mp3Player
{
public partial class frmMp3Player : Form
{
bool _IsAddFiles = false;
string[] files, paths;

public frmMp3Player()
{
InitializeComponent();
}

private void btnPlay_Click(object sender, EventArgs e)
{
_IsAddFiles = false;
OpenFileDialog opd = new OpenFileDialog();
opd.Multiselect = true;

if (opd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
files = opd.SafeFileNames;
paths = opd.FileNames;
for (int i = 0; i < files.Length; i++)
{
listBox1.Items.Add(files[i]);
}
}
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (_IsAddFiles.Equals(false))
{
int index = int.Parse(listBox1.SelectedIndex.ToString());
axWindowsMediaPlayer1.URL = paths[index];
}
else
{
string fileName = listBox1.SelectedItem.ToString();
axWindowsMediaPlayer1.URL = @"D:\Mp3Files\" + fileName;
}
}

private void btnAdd_Click(object sender, EventArgs e)
{
_IsAddFiles = true;
string file1=string.Empty;
DirectoryInfo directory = new DirectoryInfo(@"D:\Mp3Files");
FileInfo[] files = directory.GetFiles("*.mp3");
foreach (FileInfo file in files)
{
file1 = file.Name;
listBox1.Items.Add(file1);
}
}

private void frmMp3Player_Load(object sender, EventArgs e)
{
//if (axWindowsMediaPlayer1.playState != WMPLib.WMPPlayState.wmppsPlaying)

LoadSongs();
if (listBox1.Items.Count != 0)
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
listBox1.SelectedIndex = i;
break;
}
}
}

public void LoadSongs()
{
_IsAddFiles = true;
string file1 = string.Empty;
DirectoryInfo directory = new DirectoryInfo(@"D:\Mp3Files");
FileInfo[] files = directory.GetFiles("*.mp3");

foreach (FileInfo file in files)
{
file1 = file.Name;
listBox1.Items.Add(file1);
}
}
}
}

1 solution

What you need to do is subscribe to the PlayStateChange event handler. One of the parameters in the event handler is a WMPOCXEvents_PlayStateChangeEvent instance which has a newState property. If newState is 1, that means the current song has stopped so you should be able to start the next song then.
 
Share this answer
 
Comments
phil.o 6-Feb-20 2:54am    
Finally, Yoda is back to dig out and answer left-over questions :)
Pete O'Hanlon 6-Feb-20 3:17am    
It had popped to the top of the queue due to it just being updated.
phil.o 6-Feb-20 3:44am    
Yes. That isn't a bad thing, anyway, to provide answers to unanswered questions, even old ones. If somebody someday use the search function for that request, answer will prove itself useful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900