Audio

Reply

Can BGM do an intro + loop?

Is it possible to play an intro mp3 seamlessly followed by a loop mp3 for the rest of the song?

Please use plain text.

Re: Can BGM do an intro + loop?

Hi sam_p2xl

 

If have 2 mp3 files then this is easily done. You can simply instantiate 2 Bgm objects which each link to their own BGMPlayer objects. Here's how to create one of them. 

 

Bgm intro = new Bgm("/Application/intro.mp3");
BgmPlayer intro_player = intro.CreatePlayer();
intro_player.Play();

As part of your update loop you can watch the Status attribute (which is a BgmStatus enumerator) and when it reports that it's stopped you can then start to play the other audio file.

 

if(intro_player.Status == BgmStatus.Stopped)
{
      // Assume looped_audio has already been instantiated
      looped_audio.Play()
}

BgmPlayer also has a boolean attribute which you can set to true to make it loop continiously.

 

If you have any further questions please let us know :smileyhappy:

 

James

 

PlayStation®Mobile Dev Team
Please use plain text.

Level 2

Level 2
ProfessorOhki
Posts: 17
Registered: ‎19-04-2012
Message 3 of 4 (325 Views)

Re: Can BGM do an intro + loop?

[ Edited ]

I was trying to do something along these lines, but for some reason, it won't ever accept my second file as being present.  It's not the content/"copy to output" issue, I made sure of that.  In fact, setting the intro and loop players to use the same mp3 resulted in one loading fine and one failing.

 

private static BgmPlayer bgmPlayer;
private static BgmPlayer bgmPlayer2;
private static Bgm loop;
private static Bgm intro
try{
intro = new Bgm("/Application/sounds/intro.mp3");

//loop = new Bgm("/Application/sounds/loop.mp3");
loop = new Bgm("/Application/sounds/intro.mp3");

Console.WriteLine("Loading intro"); Console.Out.Flush();
bgmPlayer = intro.CreatePlayer();
bgmPlayer.Loop = false;
Console.WriteLine("Intro loaded"); Console.Out.Flush();

Console.WriteLine("Loading loop"); Console.Out.Flush();
bgmPlayer2 = loop.CreatePlayer();
bgmPlayer2.Loop = true;
Console.WriteLine("Loop loaded"); Console.Out.Flush();

 

Output:

Loading intro
Intro loaded
Loading loop
at Sce.Pss.Core.Error.ThrowNativeException (Int32 error) [0x00000] in <filename unknown>:0
at Sce.Pss.Core.Audio.Bgm.CreatePlayer () [0x00000] in <filename unknown>:0
at Sample.AppMain.Initialize () [0x00000] in <filename unknown>:0

It's the same if I use the intro.mp3 line of the loop.mp3 line.  Reversing the order of the bgmPlayer creation causes the other to fail; always the second one.  Now if I do a bgmPlayer.Dispose() before instantiating bgmPlayer2, there's no error.

 

I've got this feeling that there might be some underlying native structure that keeps two bgmPlayers from being instantiated? Or am I missing something obvious here?

Please use plain text.

Re: Can BGM do an intro + loop?

Hi,

Sorry to add to my earlier post, you will have to Dispose() of the first BgmPlayer before starting the second, as you can only have one of these in memory at one point in time (noted in the Docs: Related Pages > API Overview > Audio).
PlayStation®Mobile Dev Team
Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。