Imports System.IO

Public Class _3D_Contenttile
    Private player15 As New MediaPlayer()
    Private Sub UserControl_Loaded(sender As Object, e As RoutedEventArgs)

        Dim folderPath As String = "C:\Users\" & Environment.UserName & "\3D objects"

        Dim objFiles = Directory.GetFiles(folderPath, "*.obj", SearchOption.TopDirectoryOnly)
        itemlbl.Content = objFiles.Length & " items"


        Try
            My.Settings.Reload()
        Catch

            My.Settings.mecolor = "#19A2DE"

            Dim bluecolor As Color = CType(ColorConverter.ConvertFromString(My.Settings.mecolor), Color)
            dtile.Background = New System.Windows.Media.SolidColorBrush(bluecolor)
        End Try

        Dim d_contenttileuaTimer = New System.Windows.Threading.DispatcherTimer()
        AddHandler d_contenttileuaTimer.Tick, AddressOf d_contenttileuaTimer_Tick
        d_contenttileuaTimer.Interval = New TimeSpan(0, 0, 1)
        d_contenttileuaTimer.Start()
    End Sub

    Private Sub d_contenttileuaTimer_Tick(sender As Object, e As EventArgs)

        Dim folderPath As String = "C:\Users\" & Environment.UserName & "\3D objects"

        Dim objFiles = Directory.GetFiles(folderPath, "*.obj", SearchOption.TopDirectoryOnly)
        itemlbl.Content = objFiles.Length & " items"

        Try
            Dim mytilecolor As Color = CType(ColorConverter.ConvertFromString(My.Settings.mecolor), Color)
            dtile.Background = New System.Windows.Media.SolidColorBrush(mytilecolor)
        Catch
        End Try
    End Sub

    Private Sub PlayAccentSound()
        Try
            player15.Volume = 1.0
            player15.Open(New Uri("beltonen/wp7_pressed.mp3", UriKind.Relative))
            player15.Play()
        Catch ex As Exception
            MessageBox.Show("Error playing sound: " & ex.Message)
        End Try
    End Sub

    Private Sub UserControl_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs)
        PlayAccentSound()

    End Sub
End Class
