11 Replies - 1196 Views - Last Post: 14 December 2011 - 07:02 PM

#1 mxa92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 22-November 11

How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:03 AM

I have this opening cut-scene which is essentially a load of text appearing as though it's being written in a book, and a sound file over it (Someone reading the text that is appearing).

I would like to make it so that once the sound file is finished (Everything has been read in the book) that the screen disappears and a new background is written.

But how would I even go about doing this?

I've tried making a SoundState, and saying that when the sound is stopped, change the background, but this doesn't seem to work :\

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How to change the screen once a sound file has finished playing?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 10396
  • View blog
  • Posts: 40,050
  • Joined: 12-June 08

Re: How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:10 AM

How are you playing the sound files?
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Not here as much anymore
  • member icon

Reputation: 5978
  • View blog
  • Posts: 13,089
  • Joined: 02-June 10

Re: How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:13 AM

I'm sure there is a more elegant way than this that I don't know but...

  • Get the duration of the sound file. It should be available fairly easily since it is a displayable column from Windows Explorer.
  • Start a timer when you start the file.
  • The timer will therfore .Tick at the same time the file stops playing.
  • Stop the timer and do whatever you want.

Was This Post Helpful? 0
  • +
  • -

#4 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1490
  • View blog
  • Posts: 3,318
  • Joined: 05-April 11

Re: How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:13 AM

You need to tell us what you are using to play sounds.
Also we would like to see your code for playing sound.

Is there an event you can observe on?
Was This Post Helpful? 1
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 10396
  • View blog
  • Posts: 40,050
  • Joined: 12-June 08

Re: How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:16 AM

My thought was if the OP was using the Microsoft.DirectX.AudioVideoPlayback namespace there is an event called "stopping" that fires when the playback is done.. if that's the case then just hook up the event, watch for it, and as they say - Bob's your uncle!


http://msdn.microsof...v=vs.85%29.aspx
Was This Post Helpful? 1
  • +
  • -

#6 mxa92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 22-November 11

Re: How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:21 AM

This is all my code to create the sound files for the opening cut-scene
#region Fields
// Creating Sounds
        SoundEffect cutsceneSound, chapter1sound;        //cutsceneSound is a looped wind file over the talking which is chapter1sound.
        private SoundEffectInstance ls1;
        private SoundEffectInstance ls2;

#region Initialization
// Load the Sounds
            cutsceneSound = content.Load<SoundEffect>("Sounds/cutscene");
            chapter1sound = content.Load<SoundEffect>("Sounds/Chapter1");

            ls1 = cutsceneSound.CreateInstance();
            ls2 = chapter1sound.CreateInstance();
            ls1.IsLooped = true;

#region Update and Draw
if (level == -1)                 // Game set to start at level -1 as this is the cut-scene, level 0 is world map, and levels thereafter.
            {

                if (ls1.State == SoundState.Stopped)
                {
                    ls1.Play();
                    chapter1sound.Play();
                }

                if (ls2.State == SoundState.Stopped)
                {
                    level = 0;
                    ls1.Stop();
                }
            }


And thanks everyone for the quick replies ! :)
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 10396
  • View blog
  • Posts: 40,050
  • Joined: 12-June 08

Re: How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:25 AM

Soundeffect.. so that's what, Microsoft.Xna.Framework.Audio?
Was This Post Helpful? 0
  • +
  • -

#8 mxa92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 22-November 11

Re: How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:26 AM

View Postmodi123_1, on 30 November 2011 - 10:25 AM, said:

Soundeffect.. so that's what, Microsoft.Xna.Framework.Audio?


Yes, sorry about the lack of initial information T_T
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 10396
  • View blog
  • Posts: 40,050
  • Joined: 12-June 08

Re: How to change the screen once a sound file has finished playing?

Posted 30 November 2011 - 10:32 AM

From what I remember Soundeffect is a "set it and forget it" call. You'll have to poke around for a bit more robust option that tells you if the sound is playing, or take tlhIn's suggestion and start fiddling with timers... or make it a video of page writing and audio and go that route.
Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4734
  • View blog
  • Posts: 8,398
  • Joined: 08-June 10

Re: How to change the screen once a sound file has finished playing?

Posted 01 December 2011 - 09:26 AM

Moving to XNA.
Was This Post Helpful? 0
  • +
  • -

#11 Fib  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 162
  • View blog
  • Posts: 554
  • Joined: 12-March 09

Re: How to change the screen once a sound file has finished playing?

Posted 01 December 2011 - 01:34 PM

View Postmxa92, on 30 November 2011 - 11:21 AM, said:

This is all my code to create the sound files for the opening cut-scene
#region Fields
// Creating Sounds
        SoundEffect cutsceneSound, chapter1sound;        //cutsceneSound is a looped wind file over the talking which is chapter1sound.
        private SoundEffectInstance ls1;
        private SoundEffectInstance ls2;

#region Initialization
// Load the Sounds
            cutsceneSound = content.Load<SoundEffect>("Sounds/cutscene");
            chapter1sound = content.Load<SoundEffect>("Sounds/Chapter1");

            ls1 = cutsceneSound.CreateInstance();
            ls2 = chapter1sound.CreateInstance();
            ls1.IsLooped = true;

#region Update and Draw
if (level == -1)                 // Game set to start at level -1 as this is the cut-scene, level 0 is world map, and levels thereafter.
            {
                // ************ I think your problem lies here ************
                if (ls1.State == SoundState.Stopped)
                {
                    ls1.Play();
                    chapter1sound.Play(); // This needs to be changed to ls2.Play();
                }
                // ************ I think your problem lies here ************

                if (ls2.State == SoundState.Stopped)
                {
                    level = 0;
                    ls1.Stop();
                }
            }


And thanks everyone for the quick replies ! :)


You're not playing your ls2 SoundEffectInstance, you are playing the chapter1sound SoundEffect directly which does not offer any State checking.

I hope that helps.

This post has been edited by Fib: 01 December 2011 - 01:37 PM

Was This Post Helpful? 0
  • +
  • -

#12 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: How to change the screen once a sound file has finished playing?

Posted 14 December 2011 - 07:02 PM

Well, I'm a bit new to XNA just started a month or two ago, but why don't you just take the length of the audio in milliseconds and tell the program to do something after a certain amount of time? Not sure if there are some hidden rules in XNA, once again, very new, but I was wondering why you didn't just take the time of the audio.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1