none
Problems in using SoundPlayer Class RRS feed

  • Question

  • I'm using Visual C# 2008 Express Edition and .NET Framework Version 3.5 SP 1.
    My principal code looks like this:

    namespace test_snd_play_1
    {
     public partial class Form1 : Form
     {
      string gPieceURL;
      System.Media.SoundPlayer gSMSPlayer;

      public Form1()
      {
       InitializeComponent();

       gSMSPlayer = new System.Media.SoundPlayer();
       gPieceURL = @"D:\Musa_wav\tst\CD1_01.wav";

       gSMSPlayer.SoundLocation = gPieceURL;
       gSMSPlayer.PlaySync();
       //gSMSPlayer.Play();

      }
     }
    }

    Wav files I'm trying to play are rather large (>20Mbytes).
    Problem is that using PlaySync() function playing stops almost in the beginning of the file (<10%)
    and if I'm using Play() function my program don't know when the playing stops.

    I've been trying to disable Garbage Collector's function.

    I'm very grateful all answers.
    Thursday, July 23, 2009 9:08 PM

Answers

  • I tried to run the code using 3 other pc's without success.
    ( I was using the 'release' folder generated by Visual C# and exe file in it  and I don't know if the wrong code or resources are
      going along that folder. )
    I'll try to find another way,  directx might work.
    Fortunatly this is only my hobby.
    Thank's for your help.
     
    Sunday, July 26, 2009 7:51 PM

All replies

  • There is not a good reason why PlaySync() wouldn't work.  It is however quite unsuitable the way you are trying to use it, your form won't show up.  There is no way to get a notification that the playback is completed, the native API doesn't have one.  You could make your own by using a thread and using PlaySync.

    Hans Passant.
    Friday, July 24, 2009 1:55 AM
    Moderator
  • Thanks to nobugz for answer.
    The code I'm announcing is only for debugging ie. the simplest way ( that I found ) to play a file and
    use as few system resources as possible, anyhow the playing stops suddenly ( allways on the same position ).
    I've been testing my pc HW and System, looks like they are ok.
    If the size of a file is less than 3Mbytes the playback works ok and this makes me to suspect
    my System settings. I only don't know where to start the checkings.




    Friday, July 24, 2009 8:22 AM
  • Try another machine.

    Hans Passant.
    Friday, July 24, 2009 10:43 AM
    Moderator
  • I tried to run the code using 3 other pc's without success.
    ( I was using the 'release' folder generated by Visual C# and exe file in it  and I don't know if the wrong code or resources are
      going along that folder. )
    I'll try to find another way,  directx might work.
    Fortunatly this is only my hobby.
    Thank's for your help.
     
    Sunday, July 26, 2009 7:51 PM