[Mogre Noob] Background music

wolen

16-09-2012 11:28:54

Hi I have one simple question. How to make background music...but no just one song

private void playMusic(string path) {
using (SoundPlayer player = new SoundPlayer(path)) {
player.PlayLooping();
}
}


This is simple code but just one song...is in Mogre something simple to use?

zarfius

16-09-2012 12:17:29

Mogre has nothing to do with sound. You'll need to look into a 3rd party sound library. Maybe http://www.ambiera.com/irrklang/

wolen

16-09-2012 13:59:45

It looks nice...but I maybe I am idiot but I quickly read tutorial and some google and stackoverflow texts...but I dont know how to play whole playlist...Now I go to read it again .. it must be simple...:D...just read name of files play them and check if plays or not...if not -> play next...in loop...Am I right?

RcALTIN

16-09-2012 21:55:00

You can look for MogreFreeSL as sound lib, it's very simple to use.

zarfius

16-09-2012 22:34:34

It looks nice...but I maybe I am idiot but I quickly read tutorial and some google and stackoverflow texts...but I dont know how to play whole playlist...Now I go to read it again .. it must be simple...:D...just read name of files play them and check if plays or not...if not -> play next...in loop...Am I right?
Your logic sounds okay. You will get better answers if you try it yourself first and ask questions if you have problems.

wolen

17-09-2012 09:39:24

Solved...Thanks for help ;) Maybe it isn't very nice code but...working
using System;
using IrrKlang;
using System.IO;

namespace Mogre.Tutorials {

class SongMaker :ISoundStopEventReceiver {

protected ISoundEngine engine;
protected string path;
protected bool paused = false;
int actual = 0;
float volumeJump = 0.1f;
string[] filePaths;
ISound sound;


Random r;
public SongMaker(string path) {
this.path = path;
engine = new ISoundEngine();
filePaths = Directory.GetFiles(path);
r = new Random();
playMusic();
}

public void playMusic() {
int i;
while (actual == (i = r.Next(filePaths.Length))) { }
actual = i;
Console.WriteLine(filePaths[actual]);
engine.Play2D(filePaths[actual]);
sound = engine.Play2D(filePaths[actual]);
sound.setSoundStopEventReceiver(this);
}

public void endActualSong() {
engine.StopAllSounds();
}

private void muteSound() {
engine.SetAllSoundsPaused(true);
paused = true;
}

private void continueSound() {
engine.SetAllSoundsPaused(false);
paused = false;
}

public void pause() {
if (paused) {
continueSound();
} else {
muteSound();
}
}

public void volumeUp(){
engine.SoundVolume = changeVolume(volumeJump);
Console.WriteLine(engine.SoundVolume);
}
public void volumeDown(){
engine.SoundVolume = changeVolume(-volumeJump);
Console.WriteLine(engine.SoundVolume);
}
public float changeVolume(float f){
float help = engine.SoundVolume + f;
if (help<=0) {
return 0;
}
if (help >= 1) {
return 1;
}
return help;
}

public void OnSoundStopped(ISound sound, StopEventCause reason, object userData) {
playMusic();
}
}
}