Alarm Clock

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 4033 Views - Last Post: 17 February 2010 - 09:37 PM Rate Topic: -----

#1 camckee316  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 276
  • Joined: 29-August 08

Alarm Clock

Posted 13 February 2010 - 09:20 PM

I am trying to create an alarm clock. What the problem is, is that when I then the program where the default file is using
wmp.URL="SomeWhere\In\A\Music Folder\song.mp3"
I get this error: An error occurred creating the form. See Exception.InnerException for details. The error is: Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.

When I that line of code it runs, but when the alarm goes off there is no sound. And having a alarm clock go off with no sound is not going to get one up.

Does anyone have any ideas on what I need to do here?
I do have wmp com control on the form.

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Alarm Clock

#2 krismania  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 144
  • Joined: 03-January 10

Re: Alarm Clock

Posted 13 February 2010 - 10:35 PM

you can use:
My.Computer.Audio.Play("SomeWhere\In\A\Music Folder\song.wav")

where that path would be to a .WAV file. I think it needs to be a WAV file. but it works anyways ;)
Was This Post Helpful? 0
  • +
  • -

#3 devilydevil  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 14
  • Joined: 11-February 10

Re: Alarm Clock

Posted 13 February 2010 - 10:39 PM

The Sound file you use must be in the bin\Debug folder
My.Computer.Audio.Play("yourfile.wav")


Hope that helps :bigsmile:

This post has been edited by devilydevil: 13 February 2010 - 10:40 PM

Was This Post Helpful? -1
  • +
  • -

#4 krismania  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 144
  • Joined: 03-January 10

Re: Alarm Clock

Posted 13 February 2010 - 10:43 PM

View Postdevilydevil, on 14 February 2010 - 02:39 PM, said:

The Sound file you use must be in the bin\Debug folder
My.Computer.Audio.Play("yourfile.wav")


Hope that helps :bigsmile:


No it dosn't, at least when I used it

I used this Exact code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            My.Computer.Audio.Play("C:\Users\Admin\Desktop\GIT.wav")
        Catch Ex As Exception
            MsgBox(Ex.Message)
        End Try
    End Sub


and it played the file just fine :bananaman:
Was This Post Helpful? 1
  • +
  • -

#5 LeisureProgrammer  Icon User is offline

  • N00by VB.NET Developer
  • member icon

Reputation: 110
  • View blog
  • Posts: 588
  • Joined: 06-September 09

Re: Alarm Clock

Posted 13 February 2010 - 10:59 PM

View Postdevilydevil, on 14 February 2010 - 12:39 AM, said:

The Sound file you use must be in the bin\Debug folder

False ^
Was This Post Helpful? 0
  • +
  • -

#6 devilydevil  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 14
  • Joined: 11-February 10

Re: Alarm Clock

Posted 13 February 2010 - 11:15 PM

View PostLeisureProgrammer, on 13 February 2010 - 09:59 PM, said:

View Postdevilydevil, on 14 February 2010 - 12:39 AM, said:

The Sound file you use must be in the bin\Debug folder

False ^

Ahh, that was my computer teacher telling me that in grade 10. I'll tell him that it doesn't for future lessons on playing sound files.

Thanks :bananaman:
Was This Post Helpful? 0
  • +
  • -

#7 camckee316  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 276
  • Joined: 29-August 08

Re: Alarm Clock

Posted 13 February 2010 - 11:43 PM

That would be fine and all converting my mp3 file to wav for a default sound, But I also plan on be able to choose a song to wake up to and all my music is mp3 format.

WMP is not my default player. I have also not notice exploring windows media player folder that the wmp.exe is dimmed???? I will still lauch and is fully functional. When I try to change the way the file opens I am not to find wmp on the list.

Any one got any ideas on that?

Thanks
Was This Post Helpful? 0
  • +
  • -

#8 krismania  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 144
  • Joined: 03-January 10

Re: Alarm Clock

Posted 14 February 2010 - 01:39 AM

I found out why using the WMP control you were using before was giving an error:
this is from microsoft:

Quote

The public properties and methods of an ActiveX control can only be referenced after the ActiveX control has been instantiated and initialized completely; otherwise the AxHost.InvalidActiveXStateException exception is thrown. The AxHost.InvalidActiveXStateException exception class contains the name of the member that made the reference and the member type. The member type is one of the AxHost.ActiveXInvokeKind enumerated values.


this is from Here

what else are you doing that involves that control in the program
Was This Post Helpful? 0
  • +
  • -

#9 camckee316  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 276
  • Joined: 29-August 08

Re: Alarm Clock

Posted 15 February 2010 - 10:07 AM

Nothing that I am aware of. Here is my full code.
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'lblSystemTime.Visible = False
        'lblSundayTime.Visible = False
        Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        lblSystemTime.Text = Date.Now.ToShortTimeString
        If lblSystemTime.Text = lblSundayTime.Text Then
            Timer1.Enabled = False
            MessageBox.Show("play")
            Timer2.Enabled = True

        End If
    End Sub

    Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click
        If cbSunHr.SelectedItem = Nothing Then
            MessageBox.Show("Hour is not set")
            cbSunHr.Focus()
        ElseIf cbSunMin.SelectedItem = Nothing Then
            MessageBox.Show("Minute is not set")
            cbSunMin.Focus()
        ElseIf cbSunAP.SelectedItem = Nothing Then
            MessageBox.Show("AM or PM is not set")
            cbSunAP.Focus()
        Else
            lblSundayTime.Text = cbSunHr.SelectedItem & lblSunSeperator.Text & cbSunMin.SelectedItem & " " & cbSunAP.SelectedItem
            MessageBox.Show("The Alarm is set for " & lblSundayTime.Text & ".", "Alarm Set", MessageBoxButtons.OK)
            cbSunHr.Enabled = False
            cbSunMin.Enabled = False
            cbSunAP.Enabled = False

        End If

    End Sub

    Private Sub cbSearch_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSearch.SelectedIndexChanged
        If cbSearch.SelectedIndex = 0 Then
            'wmp=default file

        ElseIf cbSearch.SelectedIndex = 2 Then
            'wmp= search for file

        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        lblSystemTime.Text = Date.Now.ToShortTimeString

    End Sub

End Class


Was This Post Helpful? 0
  • +
  • -

#10 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 147
  • View blog
  • Posts: 983
  • Joined: 13-March 09

Re: Alarm Clock

Posted 15 February 2010 - 11:12 AM

Hm. i have done a alarm clock in VB.net before
sure. not perfect but it was done in 10 minutes and i used the WMP control and hide it. a track bar for volume and buttons for the other.
and i timer for checking time.
3 á numbUpDown.
but i dont think i still have the code =/
Was This Post Helpful? 0
  • +
  • -

#11 krismania  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 144
  • Joined: 03-January 10

Re: Alarm Clock

Posted 15 February 2010 - 01:32 PM

maybe you could try initiate the WMP control in the Load event. I think the code would be like wmp.Initiate but I am unfamiliar with the control :sleepy:
Was This Post Helpful? 1
  • +
  • -

#12 Metropoler  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 78
  • Joined: 29-December 09

Re: Alarm Clock

Posted 15 February 2010 - 01:45 PM

View Postkrismania, on 14 February 2010 - 04:43 AM, said:

My.Computer.Audio.Play("C:\Users\Admin\Desktop\GIT.wav")


You should always avoid to hardcode directories. Better way would be My.Application.Info.DirectoryPath for the application directory for example.
Was This Post Helpful? 0
  • +
  • -

#13 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 147
  • View blog
  • Posts: 983
  • Joined: 13-March 09

Re: Alarm Clock

Posted 15 February 2010 - 01:47 PM

View PostMetropoler, on 15 February 2010 - 12:45 PM, said:

View Postkrismania, on 14 February 2010 - 04:43 AM, said:

My.Computer.Audio.Play("C:\Users\Admin\Desktop\GIT.wav")


You should always avoid to hardcode directories. Better way would be My.Application.Info.DirectoryPath for the application directory for example.




or application.startuppath
Was This Post Helpful? 0
  • +
  • -

#14 camckee316  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 276
  • Joined: 29-August 08

Re: Alarm Clock

Posted 17 February 2010 - 01:42 PM

View Postkrismania, on 15 February 2010 - 12:32 PM, said:

maybe you could try initiate the WMP control in the Load event. I think the code would be like wmp.Initiate but I am unfamiliar with the control :sleepy:


That seemed to work, so far, I was able to lauch the program, set the and then when the alarm went off it played. Thank you. :bananaman: I will do some more testing later tonight or tomarrow.
Was This Post Helpful? 0
  • +
  • -

#15 camckee316  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 276
  • Joined: 29-August 08

Re: Alarm Clock

Posted 17 February 2010 - 02:11 PM

@Metropolar, and @ EndLessMind

I am unfamiliar with both these methods. I will have to check the snippets, tutorials, and google(if not found within the first two). Thank the both of you for the information and the knowledge.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2