Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embeding Background Music into VB project ?

Status
Not open for further replies.

zachlaka

Programmer
Aug 6, 2004
6
US
Is it possible to embed a sound file into vb so when the program is opened up on any computer it will play the sound w/out having to have a sound file with the program.

does it matter what file type it is mp3 wav wma even XM etc....

here is a keygen example don't know what it was coded in though. I think the sound file is xm


I would like the file to be mp3 wav or xm if possible
 
hi
i have done something similar in one of my projects, but there i used sound files, the files were stored in the Application directory and were called using app.path\file name

i have used .Wav, .Mp3 .rm files....

I m not sure what do u mean by "w/out having to have a sound file with the program."

if u need i can send u sample code...

HTH

GAzal
 
mmm... Do you mean that you want to embed the music file in your app?
 
Gazal this is not what i want to do I don't want the file to be with the progsm I want it to be embeded into the app



P1R4T3 yes thats what I meant soory I couldn't really think of how to type it! is their a way
 
try using resource file. u can search on the internet how to ue resource files in vb.
 
ok here is the code I have so far I added a resource .res file to my project and added a "COUSTOM" resource wich is the wav file any suggestions as why s code does not work I get an error this line " WindowsMediaPlayer1.Play " it says

Run-time error '-2147457259 (80004005)
Method 'play' of object 'IMediaPlayer2' failed

Of course I have a form with a media player ocx and a command button All I want to do is lay the filed

----------------------------------CODE----------------------
Private Sub Command1_Click()
Dim snd() As Byte
Dim myWav As String

myWav = App.Path & "\temp" & FreeFile() & ".wav" 'make a sequential file name
snd = LoadResData(101, "CUSTOM") 'load the raw bytes into an array
WindowsMediaPlayer1.BaseURL = "" 'reset the player

Open myWav For Binary As 1 'open, put, and close the .wav file
Put #1, , snd
Close #1

WindowsMediaPlayer1.BaseURL = myWav 'play it
WindowsMediaPlayer1.Play

End Sub
----------------------------------CODE----------------------





 
zachlaka:
do the thingie this way...

Code:
Option Explicit
Dim snd() As Byte
Dim sndFile As String

Private Sub Command1_Click()
   With WindowsMediaPlayer1
      [b].URL = sndFile[/b]
      [b].Controls.play[/b]
   End With
End Sub

Private Sub Form_Load()
   snd = LoadResData(101, "CUSTOM")
   sndFile = "F:\mySound.wav"
   Open fil For Binary As 1
      Put #1, , snd
   Close #1
End Sub

Private Sub Form_Unload(Cancel As Integer)
   Kill sndFile
End Sub

check the lines i marked bold. for further reference visit
hope it will help u.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top