Sound effects play while audio background is playing Visual Basic - vb.net

im currently new at making VB and i would like to ask if how to play sound effects while a background music is playing, for example, while a background music is playing, when i click the button it produces a sound effects. as far as i did, when i hover my mouse on the button, the current background music stops and the sound effect executes and after i hover my mouse, the background music plays agaian
here is my code..
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\auswahlrunde_loop.wav",
AudioPlayMode.BackgroundLoop)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
Private Sub Button1_MouseHover(sender As Object, e As EventArgs) Handles Button1.MouseHover
My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\Hawking.wav",
AudioPlayMode.Background)
End Sub
Private Sub Button1_MouseLeave(sender As Object, e As EventArgs) Handles Button1.MouseLeave
My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\auswahlrunde_loop.wav",
AudioPlayMode.BackgroundLoop)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub Button2_MouseHover(sender As Object, e As EventArgs) Handles Button2.MouseHover
My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\Finn.wav",
AudioPlayMode.Background)
End Sub
Private Sub Button2_MouseLeave(sender As Object, e As EventArgs) Handles Button2.MouseLeave
My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\auswahlrunde_loop.wav",
AudioPlayMode.BackgroundLoop)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
End Sub
Private Sub Button3_MouseHover(sender As Object, e As EventArgs) Handles Button3.MouseHover
My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\Homer.wav",
AudioPlayMode.Background)
End Sub
Private Sub Button3_MouseLeave(sender As Object, e As EventArgs) Handles Button3.MouseLeave
My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\auswahlrunde_loop.wav",
AudioPlayMode.BackgroundLoop)
End Sub
End Class
thanks for the replies.. cheers!

My.Computer.Audio.Play is unique (static).
You can use a SoundPlayer, that is a class, so you can instantiate it multiple times (for each sound).
Dim music As String = "" ' *.wav file location
Dim media As New Media.SoundPlayer(music)
media.Play() ' Async, creates a new thread
Dim sound As String = "" ' *.wav file location
Dim media As New Media.SoundPlayer(sound)
media.PlaySync() ' Sync, locks the current thread

Related

hello! there is someone who can help me on my project? this is my code

Public Class frmColor
Dim red, green, yellow, blue, orange As New frmChanger
Private Sub BtnRed_Click(sender As Object, e As EventArgs) Handles BtnRed.Click
frmChanger.Show(red)
End Sub
Private Sub BtnGreen_Click(sender As Object, e As EventArgs) Handles BtnGreen.Click
frmChanger.Show(green)
End Sub
Private Sub BtnYellow_Click(sender As Object, e As EventArgs) Handles BtnYellow.Click
frmChanger.Show(yellow)
End Sub
Private Sub BtnBlue_Click(sender As Object, e As EventArgs) Handles BtnBlue.Click
frmChanger.Show(blue)
End Sub
Private Sub BtnOrange_Click(sender As Object, e As EventArgs) Handles BtnOrange.Click
frmChanger.Show(orange)
End Sub
End Class
that is my code on form1....
Public Class frmChanger
Private Sub PnlRed_Paint(sender As Object, e As PaintEventArgs) Handles PnlRed.Paint
PnlRed.BackColor = Color.Red
End Sub
Private Sub PnlGreen_Paint(sender As Object, e As PaintEventArgs) Handles PnlGreen.Paint
PnlGreen.BackColor = Color.Green
End Sub
Private Sub PnlYellow_Paint(sender As Object, e As PaintEventArgs) Handles PnlYellow.Paint
PnlYellow.BackColor = Color.Yellow
End Sub
Private Sub PnlBlue_Paint(sender As Object, e As PaintEventArgs) Handles PnlBlue.Paint
PnlBlue.BackColor = Color.Blue
End Sub
Private Sub PnlOrange_Paint(sender As Object, e As PaintEventArgs) Handles PnlOrange.Paint
PnlOrange.BackColor = Color.Orange
End Sub
End Class
and this is my code on form2....
what i need is, when i clicked the btnRed on form1, on form2 only the PnlRed show..
when the BtnGreen is clicked, Pnlgreen on form2..
my problem is both panel colors show when i click only one button.. what should i do? can someone help me please.
Add a Form level variable to frmChanger with its datatype as Color and its scope as Friend (so it can be seen from frmColor). This code is using the default instance of the form. You don't really need a separate form for each color. You only want to have a different color shown. How about a single panel that will have different colors instead of multiple panels.
In the Form1 code (your frmColor)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form2.panelColor = Color.Red
Form2.Show()
End Sub
Repeat for the other buttons with = Color.Green etc.
In Form2 (your frmChanger)
Friend panelColor As Color
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Panel1.BackColor = panelColor
End Sub

How to update a progress bar while copying and pasting in Visual Basic

Hello Stack overflow community, I am here to get some help for a tool that I am programming in VB.net, I am using Visual Studio 2015 and what I am working on right now is a tool that basically creates a backup of a folder, it basically copies all files from a path that it's given in TextBox1 to the path that it's given in TextBox2, when the user presses the button "Create", it will execute this code:
My.Computer.FileSystem.CopyDirectory(TextBox1.Text, TextBox2.Text, True)
It works perfectly but what I want to do is, the progress bar that I have added to be updated during the copy paste process so the user can know that it's actually working.
The whole code is here:
Public Class Form4
Private Sub FolderBrowserDialog1_HelpRequest(sender As Object, e As EventArgs)
End Sub
Private Sub FolderBrowserDialog2_HelpRequest(sender As Object, e As EventArgs)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
FolderBrowserDialog1.ShowDialog()
End Sub
Private Sub FolderBrowserDialog1_Disposed(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = FolderBrowserDialog1.SelectedPath.ToArray
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
FolderBrowserDialog2.ShowDialog()
End Sub
Private Sub FolderBrowserDialog2_Disposed(sender As Object, e As EventArgs) Handles Button2.Click
TextBox2.Text = FolderBrowserDialog2.SelectedPath.ToArray
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Computer.FileSystem.CopyDirectory(TextBox1.Text, TextBox2.Text, True)
TextBox1.Clear()
TextBox2.Clear()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Me.Hide()
Form3.Show()
End Sub
End Class
If there's anything else that I haven't explained, let me know, thank you.

why wont this visual basic script work?

i am getting really annoyed by this piece of code for visual basic
please can you help. i have looked on YouTube and everywhere else even the vb website!!! i would really appreciate it if someone could help me out
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("Hi!!")
Timer1.Start()
End Sub
Private Sub ProgressBar1_Click(sender As Object, e As EventArgs) Handles ProgressBar1.Click
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ProgressBar1.Increment(1)
If ProgressBar1.Value = 100 Then
Timer1.Stop()
MsgBox("Jeff")
End If
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs)
End Sub
Private Function GetNumericUpDown1(v As Integer) As Boolean
End Function
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ( : ( ) Then
MessageBox.Show("Well Done!")
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
MessageBox.Show("!!Stopped!!")
Timer2.Stop()
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
ProgressBar2.Increment(0.6)
If ProgressBar2.Value = 100 Then
Timer2.Stop()
MsgBox("Jeff")
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MessageBox.Show("!!Started!!")
Timer2.Start()
End Sub
Private Sub SplitContainer1_Panel1_Paint(sender As Object, e As PaintEventArgs) Handles SplitContainer1.Panel1.Paint
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs)
End Sub
Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs)
End Sub
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
ProgressBar3.Increment(1)
If ProgressBar3.Value = 100 Then
Timer3.Stop()
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Timer3.Start()
End Sub
Private Sub ProgressBar3_Click(sender As Object, e As EventArgs) Handles ProgressBar3.Click
End Sub
End Class
BTW:this is my first post so it is probably rubbish!!
I don't have enough points to comment.
First off, as others have said we can't recreate this since we have no idea what your Form looks like or what you are expecting it to do.
Secondly, you should turn on Option Strict in the Compile section of Project properties to avoid technical errors like ProgressBar2.Increment(0.6) since 0.6 isn't a valid integer.
I threw together a TabControl (which you never mentioned in the OP) with 3 tabs and the various buttons and progress bars you list in what seemed like a logical fashion to me and it ran just fine for what code you have. Clicked the button on each tab and each progress bar eventually got to 100%. I have no idea what else you were expecting.
If you remove all the empty subs and action listeners, it would be easier to detect the problem

In Visual Studio 2013, can the button be hard coded to play a video from a known path?

I have created a simple media player using VB in Visual Studio 2013. My requirement is: just by pressing a button, I need to play the video file available at a fixed path (using the OpenFileDialog I have fixed the path). E.g. pressing a button named 'A' should play a file from 'C:/Playlists'
How can this be done? I can share my current code if needed. I'm new to VB.
Code:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
With OpenFileDialog1
.Filter = "MPEG-4|*.mp4"
.ShowDialog()
TextBox1.Text = .FileName
End With
AxWindowsMediaPlayer1.URL = (OpenFileDialog1.FileName)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
AxWindowsMediaPlayer1.Ctlcontrols.pause()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub
Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AxWindowsMediaPlayer1.settings.volume = 20
End Sub
End Class
I need buttons named A,B,C etc like play, pause which i already have. On pressing button A should play 'file_A.mp3' from 'C:\Playlist'
AxWindowsMediaPlayer1.URL = "C:\Playlist\file_A.mp3"
AxWindowsMediaPlayer1.Ctlcontrols.play()

How do you load an image to form from file via keydown?

I am trying to make a super basic program that involves a picture and sound popping up every time I click F4. I have the background of the program set to green, because I am going to be using it as a green screen for the picture. I don't have much experience with VB, but since I couldn't find a program to do this on the web, I decided to take a swing and try to make it myself. (Failed...) Anyways, this is what I got so far.
Public Class Form1
Private Sub Form1_KeyPress(KeyAscii As Integer)
If (Chr(KeyAscii) = "115") Then Form1.Picture = loadpicture("directory")
End Sub
End Class
Note: "Directory" is not what I have in loadpicture().
Try this:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True 'This enable the key event on the form (me).
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.F4 Then Me.BackgroundImage = Image.FromFile("C:\image.jpg")
End Sub
This is the final code that also includes an audio clip that plays when the key is pressed as well!
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True 'This enable the key event on the form (me).
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F4 Then Me.BackgroundImage = Image.FromFile("C:\image.jpg")
If e.KeyCode = Keys.F4 Then My.Computer.Audio.Play("C:\audio.wav", AudioPlayMode.Background)
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.F4 Then Me.BackgroundImage = Nothing
End Sub
End Class