Another question  
Author Message
babyboomer





PostPosted: Visual C++ Express Edition, Another question Top

Is there a watch list in VS express like the one in borland c++ compiler I need to watch an element to see how it changes. Thank you.

Visual Studio Express Editions13  
 
 
jrboddie





PostPosted: Visual C++ Express Edition, Another question Top

The simple answer is to use the currentMedia.duration property of the player:

dur = myPlayer.currentMedia.duration;

However, this value is not immediately available when you give the player the target file name.  The player has to digest the file before it can return the length.  (I call that "warming up.")  So I capture the PlayStateChange event for the player and grab the duration there like so:

 

 

double dur;

myPlayer.URL = filename  //will start to play

 

//Event handler for getting the duration as soon as the player has started.

private void myPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)

{

         //Wait for player to "warm up"; get the duration;

         if (e.newState == 3)

        {

              dur = myPlayer.currentMedia.duration;

              myPlayer.Ctlcontrols.pause();  //Pause the player (optional)

         }

}

 


 
 
Andreas Johansson





PostPosted: Visual C++ Express Edition, Another question Top

The express edition is a much lighter version than Visual Studio. One of the features that are not included are extensive debugging.

There is no list but you can see values of objects by hovering over them in the editor when the code is paused.

 



 
 
babyboomer





PostPosted: Visual C++ Express Edition, Another question Top

Ok thank you. Here is another question: Will the code that I wrote in express edt. work perfectly in vc++ 6
 
 
amazingsunday





PostPosted: Visual C++ Express Edition, Another question Top

How about showing those in Progressbar

Very sorry If i disappointed u. I'm just a beginner, This's my first big project.


 
 
jrboddie





PostPosted: Visual C++ Express Edition, Another question Top

One way to do this is to use a timer control to sample the Ctlcontrols.currentPosition property of the player. Send this to the Value property of the progressbar. Here is an example:

namespace WindowsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

if (openFileDialog1.ShowDialog()==DialogResult.OK)

{

myPlayer.URL = openFileDialog1.FileName;

}

}

private void myPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)

{

if (e.newState==3)

{

double dur = myPlayer.currentMedia.duration;

progressBar1.Maximum = (int)dur;

}

}

private void timer1_Tick(object sender, EventArgs e)

{

progressBar1.Value = (int)myPlayer.Ctlcontrols.currentPosition;

}

}

}

Don't forget to set the Enabled property of the timer to true.


 
 
Andreas Johansson





PostPosted: Visual C++ Express Edition, Another question Top

It might and it might not. There are differences and there is no guarantee it will work. Most code should work with no or few modifications.

 
 
babyboomer





PostPosted: Visual C++ Express Edition, Another question Top

I am having a trouble with my code:

[code]

inline double convertToDouble1(std::string& s)

{

std::istringstream i(s);

double x;

if (!(i >> x)){

try{

throw "Not a number!";

}

catch(char *g)

{ cout << "Error!" << g;

cout << " Enter a number!" << endl;

c.getReal1();

}

}

return x;

}[/code]

his is the definition of my function and here is how I use it:

[code]

void Complex::getReal1(){

complex1.real=0.0;

std::string s ;

cout << "Please enter the real value of the complex number:" << endl;

cin >> s;

double x = convertToDouble1(s);

complex1.real=x;

cout << complex1.real;

}[/code]

They do the following: Reads a string of numbers as input, changes it to a double value if it is what it is. Otherwise if the input is characters it throws an error. Here is the problem: When an error occurs for example I enter "+++" as input and it gives error and asks for the number a second time when I enter a number say "9" it gives an output of 9-9.25596e+061. The part after the number occurs after every error. What is happening and is there a solution


 
 
amazingsunday





PostPosted: Visual C++ Express Edition, Another question Top

Yes, I got it,Problem solved Thanks alot.

But I have a another problem ,And I don't want to make a new Thread . So,let me ask here,

If I want to play multiple tracks ,I have to put it in PlayList ,like this

pl = axWindowsMediaPlayer1.playlistCollection.newPlaylist("tempPlayList");

So,Everytime I play the songs It makes PlayList again and again,

So,How would I play multiple tracks without creating PlayList


 
 
jrboddie





PostPosted: Visual C++ Express Edition, Another question Top

Sorry. I don't completely understand your new question.

If you want to avoid using PlayList altogether, you could write your program to load another song when the current song finishes playing.

If your problem is that your program calls the newPlaylist() method everytime you click your "Play button", then I suggest creating another button or menu item which does nothing but load the PlayList.


 
 
Andreas Johansson





PostPosted: Visual C++ Express Edition, Another question Top

Floating point arithmetics are not exact and will only give values close to what you set it to be.



 
 
babyboomer





PostPosted: Visual C++ Express Edition, Another question Top

The problem is about string s I believe. It somehow holds the garbage value that I entered. But I can't figure a way out.
 
 
amazingsunday





PostPosted: Visual C++ Express Edition, Another question Top

Sorry for poor explanation.

Your first suggestion was my problem.

I made that the user has to choose the files which they want to play from OpenDialogBox . So that user can press Next,Previous etc. But I have to put those songs in PlayList first. My problem is that are there anyways not using PlayList Here is my codes,

private void openToolStripMenuItem_Click(object sender, EventArgs e)

{

int i = 0;

string path = axWindowsMediaPlayer1.URL;

pl = axWindowsMediaPlayer1.playlistCollection.newPlaylist("tempPlayList");

openFileDialog1.FileName = "";

openFileDialog1.Multiselect = true;

openFileDialog1.Filter = "Media Files(*.Mp3;*.Wav;*.Wma)|*.Mp3;*.Wav;*.Wma|All Files|*.*";

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

axWindowsMediaPlayer1.URL = openFileDialog1.FileName;

foreach (string s in openFileDialog1.FileNames)

{mediapath = axWindowsMediaPlayer1.newMedia(s);

pl.insertItem(i, mediapath);

}

axWindowsMediaPlayer1.currentPlaylist = pl;

}

else{}

}


 
 
jrboddie





PostPosted: Visual C++ Express Edition, Another question Top

If you want to use "Next" "Previous" etc, you will need some type of PlayList--either the one used in the MediaPlayer or one that you make and control on your own.

What is wrong with the code sample you sent


 
 
amazingsunday





PostPosted: Visual C++ Express Edition, Another question Top

Nothing wrong with the codes, But whenever I run the program it makes PlayLists. So If I go and look at the PlayList in Windows Media player there'll be a million of playlist. I just don't like that.

And you are saying I could write the program to load another song when the current song finishes playing . How would I do that without using PlayList

Could you help


 
 
jrboddie





PostPosted: Visual C++ Express Edition, Another question Top

Try something like this. This code will not create a new playlist. It will just modify the current one.

private void openToolStripMenuItem_Click(object sender, EventArgs e)

{

openFileDialog1.Multiselect = true;

if (openFileDialog1.ShowDialog()==DialogResult.OK )

{

myPlayer.currentPlaylist.clear();

foreach (string s in openFileDialog1.FileNames)

{

myPlayer.currentPlaylist.appendItem(myPlayer.newMedia(s));

}

}

}


 
 
amazingsunday





PostPosted: Visual C++ Express Edition, Another question Top

I got it, What a simple code. Thank you very much !
 
 
amazingsunday





PostPosted: Visual C++ Express Edition, Another question Top

My Progressbar doesn't end when the songs finishes playing. Is it because size of the Progressbar or something else
 
 
jrboddie





PostPosted: Visual C++ Express Edition, Another question Top

Yes. The longer the bar, the more resoluton you will have. Also consider that the ProgressBar Maximum and Value properties take integers which are cast from the doubles returned by the currentMedia.duration and currentPosition properties. You could round these values using Math.Round() to increase accuracy. As in....

progressBar1.Maximum = (int)Math.Round(myPlayer.currentMedia.duration);

and....

progressBar1.Value = (int)Math.Round(myPlayer.Ctlcontrols.currentPosition);


 
 
amazingsunday





PostPosted: Visual C++ Express Edition, Another question Top

I couldn't still do it, Progressbar didn't end when the songs finished playing. I think progressbar doesn't end the same time when the songs finishes playing. Is it
 
 
jrboddie





PostPosted: Visual C++ Express Edition, Another question Top

It should be pretty close.

I would check the duration value that you are collecting to use as the maximum value of the progress bar. Does it match the length of the music track

If the media player is visible, you can see that it has its own progress bar. Does it's behavior match yours

Check the current position value you are reading. Does it match the value shown on the media player

Are you sampling the current postion often enough What is the interval between samples