Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Click in a button, then (re)loads a music  (Read 3831 times)

0 Members and 1 Guest are viewing this topic.

jorgerosa

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • http://sites.google.com/site/jorgerosaportfolio/
    • Email
Click in a button, then (re)loads a music
« on: March 26, 2011, 11:45:43 pm »
Code: [Select]

   <SFML/Audio.hpp>

   // Global vars:
   sf::SoundBuffer buffer;
   sf::Sound sound;
   float sduration = 0.0;
   float sposition = 0.0;


   // Function that loads (and reloads) and play music:
   int playThisMusic(std::string musicPath)
   {
   sound = sf::Sound();
   buffer.LoadFromFile(musicPath.c_str());
   sound.SetBuffer(buffer);
   sound.Play();
   }


   // Main loop:
   int main()
   {
   // MY ISSUE ####### 1 #######
   // Retrieve music current time and total length:
   sduration = buffer.GetDuration();
   sposition = sound.GetPlayingOffset();

   float milliseconds  = sduration - (sduration - sposition); // Current music position
   float millisecondss = sduration; // Music length

   // The correct formula, is:
   int hours   = milliseconds/(1000*60*60);
   int minutes = (milliseconds%(1000*60*60))/(1000*60);
   int seconds = ((milliseconds%(1000*60*60))%(1000*60))/1000;  
   // Display current music position here... (in a HH:MM:SS format)

   // The correct formula, is:
   int hourss   = millisecondss/(1000*60*60);
   int minutess = (millisecondss%(1000*60*60))/(1000*60);
   int secondss = ((millisecondss%(1000*60*60))%(1000*60))/1000;  
   // Display current music length here... (in a HH:MM:SS format)

   // MY ISSUE ####### 2 #######
   // Buttons: (Pseudo code)
   // onClick1 --> playThisMusic("musics/firstSong.ogg");
   // onClick2 --> playThisMusic("musics/secondSong.ogg");
   // onClick3 --> playThisMusic("musics/thirdSong.ogg");
   // onClick4 --> playThisMusic("musics/fourthSong.ogg");
   }



I have 2 issues with SFML in my project:

1) The idea is to retrieve music current position and total length (in seconds).
(Im returning only zeros numbers).

2) And how can I click and (re)load a music?
(Allways plays first selected music, so i think im missing something to clear/delete the buffer, then refill it with the new selected music)

Thanks in advance for any solution/suggestion :)
PORTFOLIO: http://sites.google.com/site/jorgerosaportfolio
(Sorry my bad english)

 

anything