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

Author Topic: I need urgent help with a project's music player  (Read 11737 times)

0 Members and 1 Guest are viewing this topic.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: I need urgent help with a project's music player
« Reply #15 on: January 13, 2014, 03:05:28 am »
Isn't there something that I could modify within those loops so that I could still get paused text and playing text?

Yes learn C++. Sorry if this sounds rude but this is basic c++ not something special. You have a few essential logic problems.

  • You load the titlescreen texture every frame
  • You create a new sf::Music object every frame and load the file (your music will restart every frame)
  • Your drawing loops are destroying the "normal" frame procedure (Event handling, update logic, rendering) You should use if instead(but you have to fix the second point first)

I my opinion, you should buy/lend a good c++ book/ebook and return after you have solid c++ knowledge.

Here is a list with good c++ books: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list


AlexAUT

Saadin Dassum

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: I need urgent help with a project's music player
« Reply #16 on: January 24, 2014, 08:36:49 pm »
It's okay.  It's not rude.  It's true.  I have to master C++ in a better way, but for now I do need some hints.  Guys, thank you all for your help.  I figured out one of the problems.  The reason that the music wouldn't play without the glitchy drawing loop was that it was inside the window loop.  Now, I moved the music outside of the drawing loop, but the music won't switch.  I've tried a lot of things, but no matter what, the track number won't move on when outside of the window loop.  This is what my code looks like now (I simplified it to focus on the basic music problem:

#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>


int main()
{
//Rendering the Window
            sf::RenderWindow window(sf::VideoMode(1200, 400), "Smart Fast Multimedia Library Helmet");
            window.setVerticalSyncEnabled(true);
            window.setFramerateLimit(30);
//Music Status Text
            sf::Text playingText;
            sf::Font base;
            if (!base.loadFromFile("Base 02.ttf")) {
                return -1;
            }
            playingText.setFont(base);
            playingText.setString("Music is Playing");
            playingText.setCharacterSize(24);
            playingText.setColor(sf::Color::Green);
            sf::Text pausedText;
            pausedText.setString("Music is Paused");
            pausedText.setCharacterSize(24);
            pausedText.setColor(sf::Color::Green);
//Vector Container
std::vector <std::string> testingFiles;
testingFiles.push_back("Title Screen.wav");
testingFiles.push_back("firstTrack.wav");
testingFiles.push_back("secondTrack.wav");
testingFiles.push_back("thirdTrack.wav");
//Playlist track number
int trackNumber = 0;
//Opening the music file
    sf::Music testingPlaylist;
    testingPlaylist.openFromFile(testingFiles.at(trackNumber));
        //Playing Music
        testingPlaylist.play();
        //Making sure that the track moves on
        testingPlaylist.getStatus();
 if (testingPlaylist.getStatus() == sf::Music::Stopped) {
    switch (trackNumber) {
    case 0:
        trackNumber++;
    case 1:
        trackNumber++;
        break;
    case 2:
        trackNumber++;
        break;
    default:
        trackNumber = 0;
        break;
    }
    testingPlaylist.play();
 }
//Window, sprites, and textures
    while (window.isOpen())
{
    sf::Texture mainMenuTexture;
    mainMenuTexture.loadFromFile("titleScreen.png");
    sf::Sprite mainMenuSprite;
    mainMenuSprite.setTexture(mainMenuTexture);
//Main Window Loop
        sf::Event windowIsClosed;
        while (window.pollEvent(windowIsClosed))  //Making sure that the Window can close
        {
            if (windowIsClosed.type == sf::Event::Closed)
                window.close();
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && testingPlaylist.getStatus() == sf::Music::Playing) {
            testingPlaylist.pause();
        }
        //Drawing the window
        window.clear();
        window.draw(mainMenuSprite);
        window.display();
        }  /*Window Loop Ending*/

    return 0;
}  /*Main Function ending*/

 

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: I need urgent help with a project's music player
« Reply #17 on: January 25, 2014, 10:16:29 pm »
Well, your switch statement is totally unnecessary. You can accomplish the same thing more easily doing this:

if (trackNumber >= 0 && trackNumber <= 2)
    trackNumber++;

else
    trackNumber = 0;
Current Projects:
Technoport

Saadin Dassum

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: I need urgent help with a project's music player
« Reply #18 on: January 27, 2014, 03:06:29 am »
Thanks, but that's not necessarily my problem.  Both the switch and the if statement do absolutely the same thing.  My problem is that the music will not start playing again after the track number goes up.  Do you think there's a reason for that?

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: I need urgent help with a project's music player
« Reply #19 on: January 27, 2014, 03:51:58 am »
You are changing the trackNumber outside the window.isOpen() loop. So, the trackNumber will only be increased once, try using a function that increase the trackNumber and call it inside the loop, after a certain key is pressed by example.

Saadin Dassum

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: I need urgent help with a project's music player
« Reply #20 on: January 28, 2014, 03:56:59 pm »
Guys, I think this is it.  I successfully created a playlist.  I feel like I should share in case other people have the same problem.  I fixed it by placing my music.openFromFile() outside of the window loop, and my first music.play() outside of the window loop.  Inside the window loop, my condition was:
if (music.getStatus() == sf::Music::Stopped)
  if (trackNumber <= 2) {
trackNumber++;
}
else
trackNumber = 0;

music.openFromFile(testingFiles.at(trackNumber));
music.play
}
 

All I did was make the music load again after every track was changed.  Thanks for all your help guys.  I'll give credit to all of you when presenting my project! ( If you want me to).

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: I need urgent help with a project's music player
« Reply #21 on: February 01, 2014, 02:28:24 pm »
...fixed it by placing my music.openFromFile() outside of the window loop, and my first music.play() outside of the window loop.


It's good that you got it working, but hopefully this will become a lesson to you. Learn C++ now so you can be independent and won't have to depend on others telling you what to do or by trial and error. I wish you the best of luck. :)
Current Projects:
Technoport

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: I need urgent help with a project's music player
« Reply #22 on: May 24, 2014, 07:05:31 pm »
You may be interested in this little Jukebox class I wrote a while ago : https://github.com/SFML/SFML/wiki/Source%3A-Jukebox

 

anything