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();          
        }

    }
}

If I were you, the answer that came to my mind once I read your question is to compare the time of the song and from when it played.
I.e: the song length in time 2 minutes == 120 seconds and the time elapsed since it played is 60 seconds so 60\120 = 0.5 so put the Slider or the ProgressBar or what you use to its half and update it until time elapsed = the length of song.

that is exactly what i'm trying to do... my question is how and why do i get that error

"input string was not in correct format"
which appears here: Lng = Convert.ToUInt64(str.ToString());

This article has been dead for over six months. Start a new discussion instead.