Jump to content

music alarm


Guest jason76

Recommended Posts

Guest jason76

this is all a over my head to be honest as i make biscuits in my job :oops: could someone tell me how to make a music file play. got a timer thing working on phone i think.eg.if label1.text= 0 'then play a music file, and what is the timer interval to countdown in seconds.any help would be nice :?:

Link to comment
Share on other sites

Guest ChrisJM

ok, you need to get a file for sound, i can pm it to you if you like :) and you will just need to define a new sound and play it (i can explain how in a pm if you like?)

Link to comment
Share on other sites

  • 3 weeks later...
Guest bosshogg

Here's a sample in c#, hope this is what you're on about...

using System;


using System.Runtime.InteropServices;


using System.IO;






namespace MyNamespace


{


	/// <summary>


	/// Summary description for MyClass.


	/// </summary>


	public class MyClass


	{


  [DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]


  private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);


  


  [DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]


  private extern static int WCE_PlaySoundBytes (byte[] szSound, IntPtr hMod, int flags);




  public const UInt32 SND_ASYNC = 1;


  public const UInt32 SND_MEMORY = 4;


  string m_fileName;


  byte[] m_soundBytes;




  // Construct the Sound object to play sound data from the specified file.


  public MyClass(string fileName) 


  {


 	 m_fileName = fileName;


  }




  // Construct the Sound object to play sound data from the specified stream.


  public MyClass(Stream stream) 


  {


 	 // read the data from the stream


 	 m_soundBytes = new byte [stream.Length];


 	 stream.Read(m_soundBytes, 0,(int)stream.Length);


  }




  // Play the sound.


  public void Play () 


  {


 	 // If a file name has been registered, call WCE_PlaySound, 


 	 // otherwise call WCE_PlaySoundBytes.


 	 if (m_fileName != null)


    WCE_PlaySound(m_fileName, IntPtr.Zero, (int) (SND_ASYNC | SND_FILENAME));


 	 else


    WCE_PlaySoundBytes (m_soundBytes, IntPtr.Zero, (int) (SND_ASYNC | SND_MEMORY));


  }




	}


}
then call the class like this:
MyClass cls = new MyClass('chime.wav');


cls.Play();

Link to comment
Share on other sites

Guest bosshogg

no, sorry mate, I know classic vb but not vb.net...vb.net and c# are quite similar though, if I get a couple of minutes free this morning I'll see if I can convert it.

Link to comment
Share on other sites

Guest great
no, sorry mate, I know classic vb but not vb.net...vb.net and c# are quite similar though, if I get a couple of minutes free this morning I'll see if I can convert it.

i'll realy appreciate that and believe me you will solve this for many users who are wondering :D

thanks!!!

:D

Link to comment
Share on other sites

Guest bosshogg

ok, here you go, I didn't test playing from a stream but it works with a filename...

Public Class SoundPlayer




    Declare Function PlaySound Lib "CoreDLL.dll" (ByVal szSound As String, _


                                                    ByVal hMod As IntPtr, _


                                                    ByVal flags As Integer) As Integer




    Declare Function PlaySoundBytes Lib "CoreDLL.dll" (ByVal szSound As Byte(), _


                                                    ByVal hMod As IntPtr, _


                                                    ByVal flags As Integer) As Integer






    <Flags()> _


    Public Enum PlaySoundFlags


        SND_SYNC = 0


        SND_ASYNC = 1


        SND_FILENAME = &H20000


        SND_RESOURCE = &H40004


    End Enum






    Public Function Play(ByVal filename As String)




        If Len(filename) > 0 Then


            PlaySound(filename, IntPtr.Zero, PlaySoundFlags.SND_ASYNC Or PlaySoundFlags.SND_FILENAME)


        End If




    End Function




    Public Function Play(ByVal stream As Stream)


        Dim soundBytes As Byte()




        If Not stream Is Nothing Then


            ReDim soundBytes(stream.Length)


            stream.Read(soundBytes, 0, stream.Length)


            PlaySoundBytes(soundBytes, IntPtr.Zero, PlaySoundFlags.SND_ASYNC Or PlaySoundFlags.SND_RESOURCE)


        End If




    End Function




End Class
then use
Dim cls As SoundPlayer


cls = New SoundPlayer


cls.Play("chimes.wav")

to call it.

Hope that helps, look forward to seeing your app! :D

Link to comment
Share on other sites

Guest bosshogg

oh and I forgot to include

Imports System


Imports System.IO


Imports System.Runtime.InteropServices

which goes above the class declaration.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.