hi... i have a project to make an mp3 player for school.. i came up with what's under here... by basically combining parts from 3..4 players i found around the net. For now if does browsing, play, pause and close. I want to make it show position in the file, make a trackbar show progress... something like that
I found that bit of code that returns a ulong variable... but that gives an error... input string doesn't match. I've seen this same bit of code in most of the players made like this, and it seemed to work.
Can anyone help out with this?... also... explaining what that code returns and how i can transform it to smt i can display and use would e appreciated... (beginner so bare with me pls)
thanks
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.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
// private string _command;
private ulong Lng=0; //length of file
// private bool isOpen;
[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);
public Form1()
{
InitializeComponent();
}
//this should get the length of the file
private void CalculateLength()
{
StringBuilder str = new StringBuilder(128);
mciSendString("status MediaFile length", str, 128, 0);
Lng = Convert.ToUInt64(str.ToString());
label1.Text = Lng.ToString();
}
private void playbtn_Click(object sender, EventArgs e)
{
if (ofd.FileName == "")
{
if (ofd.ShowDialog() == DialogResult.OK)
{
ofd.Filter = "MP3 Files|*.mp3";
CommandString = "open " + "\"" + ofd.FileName + "\"" + " type MPEGVideo alias Mp3File";
mciSendString(CommandString, null, 0, 0);
CommandString = "play Mp3File";
mciSendString(CommandString, null, 0, 0);
playtimer.Enabled=true;
lengthbox.Text = "sdfsadfsad";
}
}
else
{
CommandString = "play Mp3File";
mciSendString(CommandString, null, 0, 0);
playtimer_Tick();
lengthbox.Text = "sdfsadfsad";
CalculateLength();
}
}
OpenFileDialog ofd = new OpenFileDialog();
string CommandString;
private void openbtn_Click(object sender, EventArgs e)
{
ofd.Filter = "Mp3 files |*.mp3";
if (ofd.ShowDialog() == DialogResult.OK)
{
CommandString = "close Mp3File";
mciSendString(CommandString, null, 0, 0);
CommandString = "open " + "\"" + ofd.FileName + "\"" + " type MPEGVideo alias Mp3File";
mciSendString(CommandString, null, 0, 0);
// this part to show length
//lengthoffile();
}
}
//pause playback
private void pausebtn_Click(object sender, EventArgs e)
{
CommandString = "pause mp3file";
mciSendString(CommandString, null, 0, 0);
}
//close program
private void closebtn_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void playtimer_Tick(/*object sender, EventArgs e*/)
{
//currentpos();
}
}
}