Author Topic: Example Playing Timer answer for you  (Read 828 times)

sak2005

  • Posts: 1007
Example Playing Timer answer for you
« on: 23 Apr '14 - 23:03 »
After very 15 secounds , song will to the playing ;D

You can modify time for before play song and after play song.

It's work, try with short song. ::)

Example:
Code: [Select]
Imports System
Imports System.Windows.Forms
Imports Un4seen.Bass

Public Class Form1
    Inherits Form
    Private lblInfo As New Label
    Private openFile As New OpenFileDialog
    Private strm As Integer
    Private file As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
    End Sub

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        lblInfo.Text = "Status: Wait! to Playing.."
        lblInfo.Location = New Point(30, 100)
        lblInfo.AutoSize = True
        Me.Controls.Add(lblInfo)
        Timer1.Interval = 1000
        AddHandler Me.ActivePlayStateChange, AddressOf Me_ActivePlayStateChange
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If openFile.ShowDialog = Windows.Forms.DialogResult.OK Then
            file = openFile.FileName
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If file IsNot Nothing Then
            If IcountUp <> 0 Then IcountUp = 0
            If strm Then Bass.BASS_StreamFree(strm)
            strm = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_DEFAULT)
            Bass.BASS_ChannelPlay(strm, True)
            SyncTime.Start()
        End If
    End Sub

    Private Sub Me_ActivePlayStateChange(ByVal sender As System.Object, ByVal e As System.EventArgs)
        TimerStart()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If file IsNot Nothing Then
            If strm Then Bass.BASS_ChannelStop(strm)
        End If
    End Sub
    '-----------------------------State Events------------------------------------
    Private WithEvents SyncTime As New Timer
    Private WithEvents Timer1 As New Timer
    Public Event ActivePlayStateChange As EventHandler
    Private IcountUp As Integer = 0
    Private IcountDown As Integer = 15  'set wait time to playing here (15 secounds)

    Private Sub SyncTime_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles SyncTime.Tick
        OnActivePlayStateChange()
    End Sub

    Public Sub TimerStart()
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
        If Bass.BASS_ChannelIsActive(strm) = BASSActive.BASS_ACTIVE_PLAYING Then
            IcountUp += 1
            lblInfo.Text = "Status: Time Playing.. " & IcountUp & " Secounds"
        End If
        If Bass.BASS_ChannelIsActive(strm) = BASSActive.BASS_ACTIVE_STOPPED Then
            IcountDown -= 1
            lblInfo.Text = "Status: Wait! CountDown to Playing: " & IcountDown & " Secounds"
            If IcountDown <= 0 Then
                Button2.PerformClick()
                Timer1.Stop()
                IcountDown = 15
                IcountUp = 0
            End If
        End If
    End Sub

    Protected Overridable Sub OnActivePlayStateChange()
        If Bass.BASS_ChannelIsActive(strm) = BASSActive.BASS_ACTIVE_PLAYING Then
            SyncTime.Stop()
            RaiseEvent ActivePlayStateChange(Me, New EventArgs)
        End If
    End Sub
End Class
« Last Edit: 24 Apr '14 - 00:19 by sak2005 »

sak2005

  • Posts: 1007
Re: Example Playing Timer answer for you
« Reply #1 on: 24 Apr '14 - 00:26 »
Timer sample, Using system time and set time for open song & radio station. (online) ;D

Code sample, add number time and click open button,
The station will auto open by timer to set. ::)

Code: [Select]
Imports System
Imports System.Windows.Forms
Imports Un4seen.Bass

Public Class Form1
    Inherits Form

    Friend WithEvents Loctime As New Timer
    Friend WithEvents tickTime As New Timer
    Private openFile As New OpenFileDialog
    Private freePlugin As Integer
    Private strm As Integer = 0
    Private file As String
    Private HH, MM, SS As Integer
    Private url As String
   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
            freePlugin = Bass.BASS_PluginLoad("bass_aac.dll")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        Button1.Text = "Open Station"
        Button2.Text = "Close Station"
        Loctime.Enabled = True
        url = "http://uk1.internet-radio.com:15476"
        ComboBox1.Text = url
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        On Error Resume Next
        If (TextBox1.Text = 0) And (TextBox2.Text = 0) And (TextBox3.Text = 0) Then
            MsgBox("You must set time before open station")
        Else
            tickTime.Enabled = True
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Bass.BASS_ChannelIsActive(strm) = BASSActive.BASS_ACTIVE_PLAYING Then
            Bass.BASS_ChannelStop(strm)
        End If
    End Sub

    Private Sub Loctime_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Loctime.Tick
        On Error Resume Next
        HH = My.Computer.Clock.LocalTime.Hour
        MM = My.Computer.Clock.LocalTime.Minute
        SS = My.Computer.Clock.LocalTime.Second
        Label1.Text = "Local Time: " & HH & ":" & MM & ":" & SS
        Label6.Text = "Status: " & StatusString
    End Sub

    Private Sub tickTime_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles tickTime.Tick
        On Error Resume Next
        If (TextBox1.Text = HH) And (TextBox2.Text = MM) And (TextBox3.Text = SS) Then
            tickTime.Enabled = False
            OpenStation()
        End If
    End Sub

    Private Sub OpenStation()
        On Error Resume Next
        If strm <> 0 Then Bass.BASS_StreamFree(strm)
        strm = Bass.BASS_StreamCreateURL(ComboBox1.Text, 0, BASSFlag.BASS_UNICODE, Nothing, IntPtr.Zero)
        If strm <> 0 Then
            Bass.BASS_ChannelPlay(strm, False)
            TextBox1.Text = "00"
            TextBox2.Text = "00"
            TextBox3.Text = "00"
        Else
            MsgBox("Error! cannot to the playing.")
        End If
    End Sub

    ReadOnly Property StatusString() As String
        Get
            Dim state As String = Nothing
            Select Case Bass.BASS_ChannelIsActive(strm)
                Case BASSActive.BASS_ACTIVE_PLAYING
                    state = "playing"
                Case BASSActive.BASS_ACTIVE_STOPPED
                    state = "stopped"
            End Select
            Return state
        End Get
    End Property

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Bass.BASS_PluginFree(freePlugin)
        Bass.BASS_Free()
    End Sub
End Class
« Last Edit: 24 Apr '14 - 06:13 by sak2005 »