Credit to C# coding from krazymir in Codeproject.
It is a simple console player that you can manipulate with the keyboard buttons.
I am posting the code also here in case you are too lazy to open the project.
I must note that while video will play as well there is sometimes that the screen will turn white (if p.e. you leave mute on for long). It must have something to do with threading but that is as far i will go for a console app
Tested in XP and VS2008
Code: in separate pages:
Edit: Tested on win7 ultimate. It actually plays better (no white screen)
Code:Imports System Imports System.Collections Imports System.ComponentModel Imports System.Data Imports System.Text Imports System.Runtime.InteropServices Imports System.Windows.Forms Module Module1 Sub Main() Dim cki As ConsoleKeyInfo ' Prevent ending if CTL+C is pressed. Console.TreatControlCAsInput = True ''''''''''''''''''''''''''''''''''''''' ' Insert Your File Below ' ''''''''''''''''''''''''''''''''''''''' Dim cout As Boolean = False Dim mp3player As New Media.MP3Player Try mp3player.Open("C:\testfile.mp3") Catch ex As Exception cout = True End Try mp3player.Play() ' exit with escape ' R Play - restart ' S Stop ' M Mute ' P Pause ' UP volume up ' Down Volume down ' Left seek left ' Right seek right Dim cpos As Int64 Try cpos = mp3player.AudioLength Catch ex As Exception ' very long file cpos = -1 End Try Dim cppl As Int64 Do If cout = True Then Exit Do End If cki = Console.ReadKey() Select Case cki.Key Case ConsoleKey.UpArrow mp3player.VolumeAll = mp3player.VolumeAll + 30 Case ConsoleKey.DownArrow mp3player.VolumeAll = mp3player.VolumeAll - 30 Case ConsoleKey.LeftArrow If cpos = -1 Then Else If mp3player.CurrentPosition > 20 Then cppl = mp3player.CurrentPosition - 5000 mp3player.Seek(cppl) End If End If Case ConsoleKey.RightArrow If cpos = -1 Then Else If mp3player.CurrentPosition < mp3player.AudioLength Then cppl = mp3player.CurrentPosition + 5000 mp3player.Seek(cppl) End If End If Case ConsoleKey.M If mp3player.MuteAll = False Then mp3player.MuteAll = True Else mp3player.MuteAll = False End If Case ConsoleKey.P mp3player.Pause() Case ConsoleKey.S mp3player.Stop() Case ConsoleKey.R mp3player.Play() End Select Console.Write(" --- You pressed ") Console.WriteLine(cki.Key.ToString) Loop While cki.Key <> ConsoleKey.Escape End Sub End Module





Reply With Quote