GOA - System.Audio.SoundLoader

SoundLoader Class


Provides implementation for the loading of sounds.

Definition

public class SoundLoader: Object

Members Table

MethodDescription
AbortCancels the loading of a sound.
EqualsOverloaded. Compares two objects to determine if they are equal. (Inherited from Object)
GetHashCodeServes as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object)
GetTypeGets the Type of the current instance. (Inherited from Object)
LoadLoads a sound at a specified url.
OnStateChangedRaises the StateChanged event.
PlayStreamPlays the sound stream located at the specified url.
ReferenceEqualsDetermines whether the specified Object instances are the same instance. (Inherited from Object)
SoundLoaderInitializes a new instance of SoundLoader.
ToStringReturns a String that represents the current Object. (Inherited from Object)
PropertyDescription
BufferingDelayGets or sets the delay of buffering of the SoundLoader.
ContentLengthGets the total size of the sound to load.
LoadedPercentageGets the loaded percentage of the sound.
LoadedSizeGets the size of the sound already loaded.
SoundGets the Sound object to load.
StateGets the state of the SoundLoader instance.
EventDescription
StateChangedHandles the changes of state of the SoundLoader instance.

Inheritance Hierarchy

Object
SoundLoader

Examples

// This sample shows how to create and use a SoundLoader instance.

 

using System;

using System.Audio;

using System.Drawing;

using System.Windows.Forms;

using System.Diagnostics;

 

namespace SampleSoundLoader

{

     public class Form1 : System.Windows.Forms.Form

     {

          private TextBox url;

          private Button load;

          private Button abort;

          private Button play;

          private TextBox log;

 

          private SoundLoader sdl = null;

 

          public Form1()

          {

               InitializeComponent();

          }

 

          private void InitializeComponent()

          {

               url= new TextBox();

               load= new Button();

               abort= new Button();

               play= new Button();

               log= new TextBox();

 

               this.SuspendLayout();

 

               url.Location= new Point(20, 20);

               url.Text= "";

               url.TextChanged += new EventHandler(on_text_changed);

               url.Width= 350;

 

               load.Location= new Point(20,url.Bottom+5);

               load.Text= "Load";

               load.Click += new EventHandler(on_load);

 

               abort.Location= new Point(load.Right+10,load.Top);

               abort.Text= "Abort";

               abort.Enabled= true;

               abort.Click += new EventHandler(on_abort);

 

               play.Location= new Point(abort.Right+10,abort.Top);

               play.Text= "Play";

               play.Enabled= true;

               play.Click += new EventHandler(on_play);

 

               log.Location= new Point(url.Left,abort.Bottom+10);

               log.Size= new Size( url.Width, 180 );

               log.Multiline= true;

               log.ScrollBars= ScrollBars.Vertical;

 

               abort.Enabled= false;

               load.Enabled= false;

               url.Enabled= true;

               play.Enabled= false;

 

               this.Controls.Add(url);

               this.Controls.Add(load);

               this.Controls.Add(abort);

               this.Controls.Add(play);

               this.Controls.Add(log);

 

               this.Text = "Form1";

               this.ResumeLayout(false);

          }

 

          void on_text_changed( object sender, EventArgs e )

          {

               load.Enabled= url.TextLength > 0;

               play.Enabled= url.TextLength > 0;

          }

 

          void on_play( object sender, EventArgs e )

          {

               Debug.Assert( sdl == null );

 

               sdl= new SoundLoader();

               sdl.PlayStream(url.Text);

               abort.Enabled= true;

               load.Enabled= false;

          }

 

          void on_load( object sender, EventArgs e )

          {

               Debug.Assert( sdl == null );

 

               sdl= new SoundLoader();

               sdl.StateChanged += new EventHandler(on_state_changed);

               print_msg("Loading: "+url.Text);

               sdl.Load(url.Text);

 

               abort.Enabled= true;

               play.Enabled= false;

               load.Enabled= false;

               url.Enabled= false;

          }

 

          void print_msg( string msg )

          {

               Debug.WriteLine(msg);

               log.AppendText( msg + "\n" );

               log.ScrollToBottom();

          }

 

          void on_state_changed( object sender, EventArgs e )

          {

               SoundLoader sdl= (SoundLoader) sender;

               switch( sdl.State )

               {

                case SoundLoaderState.Undefined:

                     print_msg("Undefined" );

                     break;

                case SoundLoaderState.Loading:

                     print_msg("Loading "+sdl.LoadedSize+"/"+sdl.ContentLength+" = "+sdl.LoadedPercentage+" ");

                     break;

                case SoundLoaderState.Completed:

                     print_msg("Completed");

                     break;

                case SoundLoaderState.Error:

                     print_msg("Error");

                     break;

               }

          }

 

          void on_abort( object sender, EventArgs e )

          {

               if( sdl == null )

                    return;

 

               sdl.Abort();

               reset();

          }

 

          void reset()

          {

               sdl= null;

               abort.Enabled= false;

               load.Enabled= true;

               play.Enabled= true;

               url.Enabled= true;

          }

 

          static void Main()

          {

               Application.Run( new Form1() );

          }

     }

}

 

Class Information

NamespaceSystem.Audio
Flash Librarycorlib.scl
Flash Library Version2.0.0.2466
Silverlight LibrarySystem.Windows.Forms.dll



© 2003-2007 NETiKA Technologies. All rights reserved.