Witam,
po godzinach programowania zrobiłem malutki odtwarzacz mp3, jest on w stylistyce material design:
Odtwarzacz nie potrzebuje dużych ilości ramu i zasobów procesora.
Program jest w fazie beta więc może mieć parę bugów za które bardo przepraszam.
Program jest wykonany w VB.NET więc wymaga .NET(4.5).
Jeszcze jest kwestia czy program zrobić całkowicie freeware czy zrobić premium albo wersje free i premium(każdy będzie pewnie sugerował freeware).
Instalator został zrobiony w Inno Setup.
Mam jedno pytanie: gdzie opublikować ostateczną wersję tak aby ktoś zauważył mój projekt?
Aby przewinąć piosenkę trzeba użyć scrolla.
Przycisk listy na razie nie działa.
Jedyny sposób odtworzenia pliku mp3 to ustawienie odtwarzacza jako domyślny i kliknięcie pliku mp3.
Program automatycznie pobiera wszystkie utwory z folderu(wykluczając utwory które są przed otworzonym utworem).
Najwięsze zużycie zasobów komputera jakie zauważyłem to:
Procesor: 2.4%
RAM: 30mb
Program jest w pełni funkcjonalny na windows 8, 8.1,10 - siódemki i xp nie testwoałem.
Jeszcze nie robiłem stress testa z dużym plikiem audio(bo takiego nie mam), testowałem pliki do max 15mb.
Program wykorzystuje bibliotekę nAudio, więc możliwe jest dodanie obsługi innych formatów.
Biblioteka która dodaje material design(MaterialSkin.dll) jest moją reedycją, oryginalna wersja jest wykonana przez Ignace Maes(moja wersja dodaje wiele różnych nowych elementów wykonanych na podstawie material design).
PS Jakby był ktoś zainteresowany moją edycją biblioteki MaterialSkin to wystarczy ją dodać do projektu w .NET(4.5) i przeciągnąć plik dll do toolboxa.
Ocenę pozostawiam wam.
SERIAL TO: BETATEST
Link do pobrania https://www.dropbox.com/s/gl7q3w6q329j21j/RavenPlayerSetupBETA.exe?dl=0
Kod programu:
Imports MaterialSkin
Imports MaterialSkin.Controls
Imports MaterialSkin.Colors
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Imports NAudio.Wave
Imports System.IO
Imports HundredMilesSoftware.UltraID3Lib
Public Class RPlayer
Inherits MaterialForm
Private PlayState As Boolean = False
Dim waveOutDevice As IWavePlayer = New WaveOut
Dim AudioFileReader As AudioFileReader
Dim mainMusicFile As String = "test.mp3"
Dim songAt As Integer = 0
Public SongArray As New ArrayList
Dim fileNoPath As String
Dim musicFolder As String
Dim totalMusicInFolder As Integer = 1
Dim totalMusic As Integer = 1
Dim typeOfLoad As String = "Nothing"
Private Sub Player_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath + "\colorConfig.conf") = False Then
My.Computer.FileSystem.WriteAllText(My.Application.Info.DirectoryPath + "\colorConfig.conf", "Default", False)
End If
Dim st As String = My.Computer.FileSystem.ReadAllText(My.Application.Info.DirectoryPath + "\colorConfig.conf")
Dim SkinManager As MaterialSkinManager = MaterialSkinManager.Instance
SkinManager.AddFormToManage(Me)
SkinManager.Theme = MaterialSkinManager.Themes.LIGHT
If st = "Default" Then
SkinManager.ColorScheme = New ColorScheme(Primary.LightBlue800, Primary.LightBlue900, Primary.LightBlue500, Accent.LightBlue200, TextShade.WHITE)
ElseIf st = "Green"
SkinManager.ColorScheme = New ColorScheme(Primary.Green800, Primary.Green900, Primary.Green500, Accent.Green200, TextShade.WHITE)
ElseIf st = "Blue"
SkinManager.ColorScheme = New ColorScheme(Primary.Blue800, Primary.Blue900, Primary.Blue500, Accent.Blue200, TextShade.WHITE)
ElseIf st = "Purple"
SkinManager.ColorScheme = New ColorScheme(Primary.Purple800, Primary.Purple900, Primary.Purple500, Accent.Purple200, TextShade.WHITE)
ElseIf st = "Cyan"
SkinManager.ColorScheme = New ColorScheme(Primary.Cyan800, Primary.Cyan900, Primary.Cyan500, Accent.Cyan200, TextShade.WHITE)
ElseIf st = "Amber"
SkinManager.ColorScheme = New ColorScheme(Primary.Amber800, Primary.Amber900, Primary.Amber500, Accent.Amber200, TextShade.WHITE)
ElseIf st = "BlueGrey"
SkinManager.ColorScheme = New ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Primary.BlueGrey200, TextShade.WHITE)
ElseIf st = "Indigo"
SkinManager.ColorScheme = New ColorScheme(Primary.Indigo800, Primary.Indigo900, Primary.Indigo500, Accent.Indigo200, TextShade.WHITE)
ElseIf st = "Yellow"
SkinManager.ColorScheme = New ColorScheme(Primary.Yellow800, Primary.Yellow900, Primary.Yellow500, Accent.Yellow200, TextShade.WHITE)
ElseIf st = "Orange"
SkinManager.ColorScheme = New ColorScheme(Primary.Orange800, Primary.Orange900, Primary.Orange500, Accent.Orange200, TextShade.WHITE)
Else
End If
Dim Colorz As New Palette
PlayPause.progressColor = Colorz.LightBlue400
If My.Application.CommandLineArgs.Count > 1 = False Then
Try
Dim Qpath As String = My.Application.CommandLineArgs(0)
If Qpath.Contains(".mp3") Then
typeOfLoad = "mp3"
mainMusicFile = Qpath
fileNoPath = Path.GetFileName(Qpath)
musicFolder = Qpath.Replace(fileNoPath, "")
PlayPause.IcoFile = My.Resources.pause
PlayPause.Refresh()
PlayState = True
Dim di As New DirectoryInfo(musicFolder)
Dim diar1 As FileInfo() = di.GetFiles()
Dim dra As FileInfo
SongArray.Add(mainMusicFile)
changeSong(0)
Dim mainSongAt As Integer = 0
Dim counter As Integer = 0
Dim mainSongFound As Boolean = False
For Each dra In diar1
If dra.FullName.Contains(".mp3") Then
If dra.FullName.Contains(".mp3") And dra.FullName = mainMusicFile = False Then
If mainSongFound = True Then
SongArray.Add(dra.FullName)
End If
Else
mainSongAt = counter
mainSongFound = True
End If
counter += 1
End If
Next
totalMusicInFolder = counter
totalMusic = counter - mainSongAt
End If
Catch ex As Exception
End Try
End If
End Sub
Sub changeSong(songIndex As Integer)
If typeOfLoad = "mp3" Then
Try
If waveOutDevice.PlaybackState = PlaybackState.Paused Or waveOutDevice.PlaybackState = PlaybackState.Playing Then
AudioFileReader.Dispose()
waveOutDevice.Stop()
waveOutDevice.Dispose()
GetTime.Stop()
End If
PlayPause.Progress = 0
songAt = songIndex
Dim sTitle As String = "No Name"
Dim sSinger As String = ""
Dim sAlbum As String = ""
Dim sYear As String = ""
Dim sComm As String = ""
Dim MP3Tag As New UltraID3
MP3Tag.Read(SongArray(songAt))
Try
Dim pics = MP3Tag.ID3v2Tag.Frames.GetFrames(CommonMultipleInstanceID3v2FrameTypes.Picture)
AlbumPic.Image = CType(pics(0), ID3v2PictureFrame).Picture
Catch ex As Exception
AlbumPic.Image = My.Resources.FlatCD
End Try
Try
sTitle = MP3Tag.Title
sSinger = MP3Tag.Artist
sAlbum = MP3Tag.Album
Catch ex As Exception
End Try
TitleLabel.Text = sTitle
AlbumName.Text = sAlbum
ArtistName.Text = sSinger
waveOutDevice = New WaveOut
AudioFileReader = New AudioFileReader(SongArray(songAt))
waveOutDevice.Init(AudioFileReader)
waveOutDevice.Play()
GetTime.Start()
Catch ex As Exception
songAt = 0
waveOutDevice.Stop()
End Try
End If
End Sub
Public Function RotateImg(ByVal bmpimage As Image, ByVal angle As Single) As Image
Dim w As Integer = bmpimage.Width
Dim h As Integer = bmpimage.Height
Dim pf As PixelFormat = Nothing
pf = bmpimage.PixelFormat
Dim tempImg As New Bitmap(w, h, pf)
Dim g As Graphics = Graphics.FromImage(tempImg)
g.DrawImageUnscaled(bmpimage, 1, 1)
g.Dispose()
Dim path As New GraphicsPath()
path.AddRectangle(New RectangleF(0.0F, 0.0F, w, h))
Dim mtrx As New Matrix()
'Using System.Drawing.Drawing2D.Matrix class
mtrx.Rotate(angle)
Dim rct As RectangleF = path.GetBounds(mtrx)
Dim newImg As New Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf)
g = Graphics.FromImage(newImg)
g.TranslateTransform(-rct.X, -rct.Y)
g.RotateTransform(angle)
g.InterpolationMode = InterpolationMode.HighQualityBilinear
g.DrawImageUnscaled(tempImg, 0, 0)
g.Dispose()
tempImg.Dispose()
Dim imgA As Image = newImg
Return imgA
End Function
Private Function CropImage(ByRef bmp As Bitmap, ByVal cropX As Integer, ByVal cropY As Integer, ByVal cropWidth As Integer, ByVal cropHeight As Integer) As Bitmap
Dim rect As New Rectangle(cropX, cropY, cropWidth, cropHeight)
Dim cropped As Bitmap = bmp.Clone(rect, bmp.PixelFormat)
Dim imagA As Bitmap = cropped
Return cropped
End Function
Private Sub PlayPause_Click(sender As Object, e As MouseEventArgs) Handles PlayPause.MouseWheel, PlayPause.Click
If typeOfLoad = "mp3" Then
If e.Delta > 0 Then
Try
If waveOutDevice.PlaybackState = PlaybackState.Stopped = False Then
If AudioFileReader.CurrentTime.TotalSeconds + 1 >= AudioFileReader.TotalTime.TotalSeconds = False Then
AudioFileReader.CurrentTime = New TimeSpan(AudioFileReader.CurrentTime.Hours, AudioFileReader.CurrentTime.Minutes, AudioFileReader.CurrentTime.Seconds + 1)
Else
PlayPause.Progress = 100
End If
End If
Catch ex As Exception
PlayPause.Progress = 100
End Try
Else
Try
If waveOutDevice.PlaybackState = PlaybackState.Stopped = False Then
If AudioFileReader.CurrentTime.TotalSeconds - 1 < 0 = False Then
AudioFileReader.CurrentTime = New TimeSpan(AudioFileReader.CurrentTime.Hours, AudioFileReader.CurrentTime.Minutes, AudioFileReader.CurrentTime.Seconds - 1)
End If
End If
Catch ex As Exception
PlayPause.Progress = 100
End Try
End If
End If
End Sub
Private Sub PlayPause_Click(sender As Object, e As EventArgs) Handles PlayPause.Click
If typeOfLoad = "mp3" Then
If PlayState = False Then
PlayPause.IcoFile = My.Resources.pause
PlayPause.Refresh()
PlayState = True
If waveOutDevice.PlaybackState = PlaybackState.Paused Then
AudioFileReader.CurrentTime = New TimeSpan(AudioFileReader.CurrentTime.Hours, AudioFileReader.CurrentTime.Minutes, AudioFileReader.CurrentTime.Seconds + 2)
waveOutDevice.Play()
GetTime.Start()
End If
Else
PlayPause.IcoFile = My.Resources.play
PlayPause.Refresh()
PlayState = False
waveOutDevice.Pause()
GetTime.Stop()
End If
End If
End Sub
Private Sub GetTime_Tick(sender As Object, e As EventArgs) Handles GetTime.Tick
If typeOfLoad = "mp3" Then
Try
SongAtLabel.Text = (1 + songAt).ToString + " of " + totalMusic.ToString
PlayPause.Progress = AudioFileReader.CurrentTime.TotalSeconds / AudioFileReader.TotalTime.TotalSeconds * 100
Dim seconds As String = ""
Dim minutes As String = ""
Dim hours As String = ""
If AudioFileReader.TotalTime.Seconds > 0 Or AudioFileReader.TotalTime.Minutes > 0 Or AudioFileReader.TotalTime.Hours > 0 Then
seconds = AudioFileReader.CurrentTime.Seconds.ToString.PadLeft(2, "0")
End If
If AudioFileReader.TotalTime.Minutes > 0 Or AudioFileReader.TotalTime.Hours > 0 Then
If AudioFileReader.CurrentTime.Minutes > 0 Then
minutes = AudioFileReader.CurrentTime.Minutes.ToString.PadLeft(2, "0") + ":"
Else
minutes = "00:"
End If
End If
If AudioFileReader.TotalTime.Hours > 0 Then
If AudioFileReader.CurrentTime.Minutes > 0 Then
hours = AudioFileReader.CurrentTime.Hours.ToString.PadLeft(2, "0") + ":"
Else
hours = "00:"
End If
End If
DurationSong.Text = hours + minutes + seconds
If PlayPause.Progress >= 100 Then
If SongArray.Count - 1 = songAt = False Then
songAt += 1
Else
songAt = 0
End If
changeSong(songAt)
End If
Catch ex As Exception
End Try
End If
End Sub
Const Rad2Deg As Double = 180.0 / Math.PI
Const Deg2Rad As Double = Math.PI / 180.0
Private Function Angle(start As Point, [end] As Point) As Double
Return Math.Atan2(start.Y - [end].Y, [end].X - start.X) * Rad2Deg
End Function
Private Sub NextSong_Click(sender As Object, e As EventArgs) Handles NextSong.Click
If typeOfLoad = "mp3" Then
TitleLabel.Location = New Point(0, TitleLabel.Location.Y)
PlayState = True
PlayPause.IcoFile = My.Resources.pause
If PlayState = False Then
PlayState = True
End If
If songAt = SongArray.Count - 1 Then
songAt -= songAt
PlayState = False
Else
songAt += 1
End If
changeSong(songAt)
PlayPause.Select()
End If
End Sub
Private Sub PreviousSong_Click(sender As Object, e As EventArgs) Handles PreviousSong.Click
If typeOfLoad = "mp3" Then
TitleLabel.Location = New Point(0, TitleLabel.Location.Y)
PlayState = True
PlayPause.IcoFile = My.Resources.pause
If PlayState = False Then
PlayState = True
End If
If songAt = 0 Then
songAt = SongArray.Count - 1
Else
songAt -= 1
End If
changeSong(songAt)
PlayPause.Select()
End If
End Sub
Private Sub TextMarquee_Tick(sender As Object, e As EventArgs) Handles TextMarquee.Tick
Dim g As Graphics = TitleLabel.CreateGraphics
If g.MeasureString(TitleLabel.Text, TitleLabel.Font).Width - 5 > TitleLabel.Width Or TitleLabel.Width > Panel1.Width Then
TitleLabel.Parent = Panel1
TitleLabel.Width = g.MeasureString(TitleLabel.Text, TitleLabel.Font).Width - 5
If TitleLabel.Location.X + TitleLabel.Width < 0 Then
TitleLabel.Location = New Point(Panel1.Width, TitleLabel.Location.Y)
Else
TitleLabel.Location = New Point(TitleLabel.Location.X - 1, TitleLabel.Location.Y)
End If
End If
If g.MeasureString(AlbumName.Text, AlbumName.Font).Width - 10 > AlbumName.Width Or AlbumName.Width > Panel2.Width Then
AlbumName.Parent = Panel2
AlbumName.Width = g.MeasureString(AlbumName.Text, AlbumName.Font).Width - 10
If AlbumName.Location.X + AlbumName.Width < 0 Then
AlbumName.Location = New Point(Panel2.Width, AlbumName.Location.Y)
Else
AlbumName.Location = New Point(AlbumName.Location.X - 1, AlbumName.Location.Y)
End If
End If
If g.MeasureString(ArtistName.Text, ArtistName.Font).Width - 10 > ArtistName.Width Or ArtistName.Width > Panel3.Width Then
ArtistName.Parent = Panel3
ArtistName.Width = g.MeasureString(ArtistName.Text, ArtistName.Font).Width - 5
If ArtistName.Location.X + ArtistName.Width < 0 Then
ArtistName.Location = New Point(Panel3.Width, ArtistName.Location.Y)
Else
ArtistName.Location = New Point(ArtistName.Location.X - 1, ArtistName.Location.Y)
End If
End If
End Sub
End Class
Kiedyś zrobiłem jeszcze inny odtwarzacz ale porzuciłem go, ma on trochę większą funkcjonalność i pobiera więcej zasobów. Sprawdziłem czy działa i postanowiłem go dodać do postu.
Patrząc na komentarz @Patryk27 postanowiłem dodać go do postu, podpowiedzcie co z tej wersji programu dodać do wersji powyżej, a może zakończyć rozwijanie nowej wersji i ulepszyć starą.
Link do starej wersji: https://www.dropbox.com/s/kylfc377fpciggb/RavenPlayer%20Aternative%28HEAVY%20VERSION%29.zip?dl=0
Screenshot starej wersji:
UWAGA!!! NIE REKOMENDUJĘ KORZYSTANIA Z WERSJI PO WYŻEJ JEST ONA NIE STABILNA I MOŻE CZASAMI NIE DZIAŁAĆ.