5 Replies - 12513 Views - Last Post: 14 February 2010 - 09:55 PM Rate Topic: -----

#1 systemerror   User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

C# Play mp3 From Source

Post icon  Posted 22 September 2009 - 02:35 AM

This is the code I got

System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
			myPlayer.SoundLocation = "Alarm_clock";
			myPlayer.Play();


I want it to play that random mp3 from the program but for some reason its not working, its suppose to just play the mp3, can some one please help me?
Is This A Good Question/Topic? 0
  • +

Replies To: C# Play mp3 From Source

#2 janne_panne   User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: C# Play mp3 From Source

Posted 22 September 2009 - 02:52 AM

Set a full filepath instead of just "Alarm_clock". The program doesn't know where the Alarm_clock is or what's its extension.
Was This Post Helpful? 0
  • +
  • -

#3 systemerror   User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Play mp3 From Source

Posted 22 September 2009 - 03:02 AM

View Postjanne_panne, on 22 Sep, 2009 - 01:52 AM, said:

Set a full filepath instead of just "Alarm_clock". The program doesn't know where the Alarm_clock is or what's its extension.


Yeh that's the problem, I don't know how to send it to the resource file from the resources
Was This Post Helpful? 0
  • +
  • -

#4 janne_panne   User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: C# Play mp3 From Source

Posted 22 September 2009 - 03:44 AM

If the sound file is in resources, you can use Stream property to play the file:

			System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
			myPlayer.Stream = Properties.Resources.soundfile;
			myPlayer.Play();


Was This Post Helpful? 0
  • +
  • -

#5 systemerror   User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Play mp3 From Source

Posted 22 September 2009 - 05:22 PM

View Postjanne_panne, on 22 Sep, 2009 - 02:44 AM, said:

If the sound file is in resources, you can use Stream property to play the file:

			System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
			myPlayer.Stream = Properties.Resources.soundfile;
			myPlayer.Play();



I try this

myPlayer.Stream = Properties.Resources.Alarm_clock;

but it comes up with an error like
Posted Image
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Zach*


Reputation:

Re: C# Play mp3 From Source

Posted 14 February 2010 - 09:55 PM

In order to use the above method, the resource must be a .wav file.

This, however, makes it quite a large file, as .wav files are uncompressed. Ten seconds of a wav is about the size of a 4 minute mp3, in some cases.
Was This Post Helpful? 0

Page 1 of 1