Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sound effect in windows phone 7

I am trying to play a music from the phone song collection.

Does the sound effect properties support playing from the song collection?

Previously i used the media player to play the song but i want to set the music to not pause-able.

Code for sound effect : SoundEffect effect; SoundEffectInstance instance;

        effect = SoundEffect.FromStream(ml.Songs[songSelectedIndex]);
        instance = effect.CreateInstance();
        instance.IsLooped = true;
        instance.Volume = 1.0f;
        instance.Pitch = 1.0f;
        instance.Play();

Code for media library :

        using (var ml = new MediaLibrary())

        {
            FrameworkDispatcher.Update();
            MediaPlayer.Play(ml.Songs[songSelectedIndex]);
            MediaPlayer.IsRepeating = true;
        }
like image 299
beny lim Avatar asked Nov 13 '22 19:11

beny lim


1 Answers

A Song is a class that contains the music stream and can only be played with the Media Player. The reason your code isn't working is because the FromStream method requires the stream to be:

  • A PCM wave file
  • Mono or stereo
  • 8 or 16 bit
  • Between 8,000 Hz and 48,000 Hz sample rate

I haven't tried this, nor know what the certification guidelines make of it, but you might be able to make the music unpauseable with the MediaPlayer. Handle the MediaStateChanged event and check if the music is paused. If it is, then call the Resume method to continue playing.

Edit - Update with code:

Handling the MediaStageChanged event is the same as any other event.

MediaPlayer.MediaStateChanged += new EventHandler<EventArgs>(MediaPlayer_MediaStateChanged);

In your event handler, do this:

void MediaPlayer_MediaStateChanged(object sender, EventArgs e)
{
    if (MediaPlayer.State == MediaState.Paused) MediaPlayer.Resume();
}
like image 189
keyboardP Avatar answered Dec 25 '22 06:12

keyboardP