Playing sound, stop after 5~ secconds

Greetings, i’m starting to learn Panda3d, and i’m currently experimenting many features by adding them to the Hello World example.

Now, i’ve tried the audio manager, and tried to play an mp3 song, just for testing purpose, and, the song stop playing after a few secconds, the program keep running normaly, here’s the code

#include "pandaFramework.h"
#include "pandaSystem.h"
#include "orthographicLens.h"
#include "genericAsyncTask.h"
#include "asyncTaskManager.h"
#include "audioManager.h"
#include "cIntervalManager.h"
#include "cLerpNodePathInterval.h"
#include "cMetaInterval.h"

// Global stuff
PandaFramework framework;
PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr();
PT(ClockObject) globalClock = ClockObject::get_global_clock();
NodePath camera;
// Task to move the camera
AsyncTask::DoneStatus SpinCameraTask(GenericAsyncTask* task, void* data) {
  double time = globalClock->get_real_time();
  double angledegrees = time * 6.0;
  double angleradians = angledegrees * (3.14 / 180.0);
  camera.set_pos(20*sin(angleradians),-20.0*cos(angleradians),3);
  camera.set_hpr(angledegrees, 0, 0);

  return AsyncTask::DS_cont;

}

int main(int argc, char *argv[]) {
  // Open a new window framework and set the title
  framework.open_framework(argc, argv);
  framework.set_window_title("My Panda3D Window");


  PT(AudioManager) AM = AudioManager::create_AudioManager();
PT(AudioSound) mySound = AM->get_sound("/home/pierrick/Music/test.mp3") ;
mySound->play();


  // Open the window
  WindowFramework *window = framework.open_window();
  camera = window->get_camera_group(); // Get the camera and store it

  // Load the environment model
  NodePath environ = window->load_model(framework.get_models(),
    "models/environment");
  environ.reparent_to(window->get_render());
  environ.set_scale(0.25 , 0.25, 0.25);
  environ.set_pos(-8, 42, 0);

  // Load our panda
  NodePath pandaActor = window->load_model(framework.get_models(),
    "panda-model");
  pandaActor.set_scale(0.005);
  pandaActor.reparent_to(window->get_render());

  // Load the walk animation
  window->load_model(pandaActor, "panda-walk4");
  window->loop_animations(0);

  // Create the lerp intervals needed to walk back and forth
  PT(CLerpNodePathInterval) pandaPosInterval1, pandaPosInterval2,
    pandaHprInterval1, pandaHprInterval2;
  pandaPosInterval1 = new CLerpNodePathInterval("pandaPosInterval1",
    13.0, CLerpInterval::BT_no_blend,
    true, false, pandaActor, NodePath());
  pandaPosInterval1->set_start_pos(LPoint3f(0, 10, 0));
  pandaPosInterval1->set_end_pos(LPoint3f(0, -10, 0));

  pandaPosInterval2 = new CLerpNodePathInterval("pandaPosInterval2",
    13.0, CLerpInterval::BT_no_blend,
    true, false, pandaActor, NodePath());
  pandaPosInterval2->set_start_pos(LPoint3f(0, -10, 0));
  pandaPosInterval2->set_end_pos(LPoint3f(0, 10, 0));

  pandaHprInterval1 = new CLerpNodePathInterval("pandaHprInterval1", 3.0,
    CLerpInterval::BT_no_blend,
    true, false, pandaActor, NodePath());
  pandaHprInterval1->set_start_hpr(LPoint3f(0, 0, 0));
  pandaHprInterval1->set_end_hpr(LPoint3f(180, 0, 0));

  pandaHprInterval2 = new CLerpNodePathInterval("pandaHprInterval2", 3.0,
    CLerpInterval::BT_no_blend,
    true, false, pandaActor, NodePath());
  pandaHprInterval2->set_start_hpr(LPoint3f(180, 0, 0));
  pandaHprInterval2->set_end_hpr(LPoint3f(0, 0, 0));

  // Create and play the sequence that coordinates the intervals
  PT(CMetaInterval) pandaPace;
  pandaPace = new CMetaInterval("pandaPace");
  pandaPace->add_c_interval(pandaPosInterval1, 0,
    CMetaInterval::RS_previous_end);
  pandaPace->add_c_interval(pandaHprInterval1, 0,
    CMetaInterval::RS_previous_end);
  pandaPace->add_c_interval(pandaPosInterval2, 0,
    CMetaInterval::RS_previous_end);
  pandaPace->add_c_interval(pandaHprInterval2, 0,
    CMetaInterval::RS_previous_end);
  pandaPace->loop();

  // Add our task.
  taskMgr->add(new GenericAsyncTask("Spins the camera",
    &SpinCameraTask, (void*) NULL));


PT(OrthographicLens) lens = new OrthographicLens();
lens->set_film_size(20, 15); // Or whatever is appropriate for your scene
window->get_camera(0)->set_lens(lens);
  // This is a simpler way to do stuff every frame,
  // if you're too lazy to create a task.
  Thread *current_thread = Thread::get_current_thread();
  while(framework.do_frame(current_thread)) {
    // Step the interval manager
    CIntervalManager::get_global_ptr()->step();
  }

  framework.close_framework();
  return (0);
}

Anyone know what could be the problem?

By the way! i’m running…

Ubuntu 11.04 64bit
Panda3D 1.7.2 installed via .deb
Code::Block 10.05
GCC… uhh… the one that is bundle’d with ubuntu 11.04 <.<

Thanks for any help!

That’s a lot of code to pore through. Do you suppose you could distill it down to just a bit of code that loads a sound and plays it?

David

#include "pandaFramework.h"
#include "pandaSystem.h"
 #include "audioManager.h"
PandaFramework framework;

int main(int argc, char *argv[]) {
    // Load the window and set its title.
    framework.open_framework(argc, argv);
    framework.set_window_title("My Panda3D Window");
    WindowFramework *window = framework.open_window();

    // Load the environment model.
    NodePath environ = window->load_model(framework.get_models(), "models/environment");
    // Reparent the model to render.
    environ.reparent_to(window->get_render());
    // Apply scale and position transforms to the model.
    environ.set_scale(0.25, 0.25, 0.25);
    environ.set_pos(-8, 42, 0);



// EVERYTHING CONCERNING SOUND IS BELOW
    PT(AudioManager) AM = AudioManager::create_AudioManager();
PT(AudioSound) mySound = AM->get_sound("/home/pierrick/Music/test.mp3") ;
mySound->play();
// EVERYTHING CONCERNING SOUND IS ABOVE



    // Run the engine.
    framework.main_loop();
    // Shut down the engine when done.
    framework.close_framework();
    return (0);
}

Still doing same thing, that one is the hello world part where you only see grass with no camera movement

Well, I don’t see anything wrong in that code; and in fact it works fine for me when I try to run it (substituting my own mp3 file, of course).

So, the next question is, does it work for you with a different mp3 file? How about if you switch the audio layer from OpenAL to FMod (or vice-versa)?

David

Hi

Maybe this sound file will need the task to call AudioManager update in order to keep it playing.

Ah, thank you! That’s of course the answer. I forgot about it because it happens automatically when the AudioManager is created in Python. But, of course, when you create your own AudioManager you have to add a task to keep it updated.

Some audio libraries can play without this task, which is also why I didn’t notice the problem when I tried it too. :slight_smile:

David