An installer for this script can be downloaded from my website which I suggest because there are mutiple files as well an ini entry.
Code: Select all
'
' MediaMonkey Script
'
' NAME: Previewer 2.9
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 26/07/2014
'
' Thanks to Psyxonova for this help with the design of this script
' Thanks to MoDementia who added check/disable/re-enable for AutoDJ and AutoRateSongs
' Thanks to Nanya who helped make the progress bar editable during preview
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
'
' NOTE: This script switches off AutoDJ, AutoRateSongs, AutoAlbumDJ, ScrobblerDJ and RatePlayedSong
' It restores their previous state afterwards though! :)
'
' [Previewer]
' FileName=Previewer.vbs
' ProcName=Previewer
' Order=10
' DisplayName=Previewer
' Description=Preview a track without disturbing now playing
' Language=VBScript
' ScriptType=0
'
' FIXES: Added ability to move progress bar during preview (thanks to Nanya)
'
Option Explicit
Dim ManualChange : ManualChange = True
Sub Toolbar(but)
Call Previewer()
End Sub
Sub Previewer
If SDB.SelectedSonglist.Count = 1 Then
'get status and switch off other scripts
Dim Regs : Set Regs = SDB.Registry
If Regs.OpenKey("Auto Rating", True) Then
Dim autoratesongson : autoratesongson = Regs.IntValue("os00")
If Regs.IntValue("os00") = 1 Then
Regs.IntValue("os00") = 0
Regs.CloseKey
End If
End If
Dim autodj : autodj = SDB.Player.isAutoDJ
If autodj Then
SDB.Player.isAutoDJ = False
End If
Dim scrobbler : scrobbler = SDB.IniFile.StringValue("ScrobblerDJ","Enabled")
If scrobbler = "1" Then
SDB.IniFile.StringValue("ScrobblerDJ","Enabled") = "0"
End If
Dim autoalbum : autoalbum = SDB.IniFile.StringValue("AutoAlbumDJ","Enabled")
If autoalbum = "1" Then
SDB.IniFile.StringValue("AutoAlbumDJ","Enabled") = 0
End If
Dim crossfade : crossfade = SDB.Player.isCrossfade
If crossfade Then
SDB.Player.isCrossfade = False
End If
Dim ratesong : ratesong = SDB.IniFile.BoolValue("RatePlayedSong","Enabled")
If ratesong Then
SDB.IniFile.BoolValue("RatePlayedSong", "Enabled") = False
End If
'store player status
Dim playing : playing = SDB.Player.isPlaying
Dim paused : paused = SDB.Player.isPaused
If playing Or paused Then
Dim curi : curi = SDB.Player.CurrentSongIndex
Dim curp : curp = SDB.Player.PlaybackTime
SDB.Player.Stop
End If
'play preview track
Dim newi : newi = SDB.Player.PlaylistCount
SDB.Player.PlaylistAddTrack(SDB.SelectedSonglist.Item(0))
SDB.Player.CurrentSongIndex = newi
SDB.Player.Play
'create preview form
Dim midp : midp = 200
Dim bheight : bheight = 23
Dim bwidth : bwidth = 35
Dim Form : Set Form = SDB.UI.NewForm
Form.Common.SetRect 100, 100, (2*midp)+15, 200
Form.BorderStyle = 3 ' Non-Resizable
Form.FormPosition = 4 ' Screen Center
Form.Caption = "Previewer"
Dim Label2 : Set Label2 = SDB.UI.NewLabel(Form)
Label2.Caption = "Title: "&SDB.Player.CurrentSong.Title
Label2.Common.Left = 10
Label2.Common.Top = 14
Dim Label1 : Set Label1 = SDB.UI.NewLabel(Form)
Label1.Caption = "Artist: "&SDB.Player.CurrentSong.ArtistName
Label1.Common.Left = 10
Label1.Common.Top = Label2.Common.Top + Label2.Common.Height +10
Dim Btn3 : Set Btn3 = SDB.UI.NewButton(Form)
Btn3.Caption = "&Pause"
Btn3.Common.Height = bheight
Btn3.Common.Width = bwidth+20
Btn3.Common.Top = Label1.Common.Top + Label1.Common.Height +10
Btn3.Common.Left = midp - Int(Btn3.Common.Width/2)
Btn3.Common.ControlName = "playButton"
Btn3.UseScript = Script.ScriptPath
Btn3.OnClickFunc = "playPause"
Dim Btn2 : Set Btn2 = SDB.UI.NewButton(Form)
Btn2.Caption = "-5s"
Btn2.Common.Height = bheight
Btn2.Common.Width = bwidth
Btn2.Common.Top = Btn3.Common.Top
Btn2.Common.Left = midp - Int(Btn3.Common.Width/2) - bwidth -10
Btn2.UseScript = Script.ScriptPath
Btn2.OnClickFunc = "seekB05"
Dim Btn1 : Set Btn1 = SDB.UI.NewButton(Form)
Btn1.Caption = "-30s"
Btn1.Common.Height = bheight
Btn1.Common.Width = bwidth
Btn1.Common.Top = Btn3.Common.Top
Btn1.Common.Left = midp - Int(Btn3.Common.Width/2) - (bwidth*2) -20
Btn1.UseScript = Script.ScriptPath
Btn1.OnClickFunc = "seekB30"
Dim Btn4 : Set Btn4 = SDB.UI.NewButton(Form)
Btn4.Caption = "+5s"
Btn4.Common.Height = bheight
Btn4.Common.Width = bwidth
Btn4.Common.Top = Btn3.Common.Top
Btn4.Common.Left = midp + Int(Btn3.Common.Width/2) +10
Btn4.UseScript = Script.ScriptPath
Btn4.OnClickFunc = "seekF05"
Dim Btn5 : Set Btn5 = SDB.UI.NewButton(Form)
Btn5.Caption = "+30s"
Btn5.Common.Height = bheight
Btn5.Common.Width = bwidth
Btn5.Common.Top = Btn3.Common.Top
Btn5.Common.Left = midp + Int(Btn3.Common.Width/2) + bwidth +20
Btn5.UseScript = Script.ScriptPath
Btn5.OnClickFunc = "seekF30"
Dim PosBar : Set PosBar = SDB.UI.NewTrackBar(Form)
PosBar.Horizontal = True
PosBar.MinValue = 0
PosBar.MaxValue = 1000
PosBar.Value = 0
PosBar.Common.Top = Btn3.Common.Top + bheight
PosBar.Common.Left = 20
PosBar.Common.Height = 25
PosBar.Common.Width = (midp - PosBar.Common.Left)*2
PosBar.Common.Enabled = True
Call Script.RegisterEvent(PosBar,"OnChange","OnSeek")
Set SDB.Objects("PreviewerPosBar") = PosBar
Dim BtnPlayNow : Set BtnPlayNow = SDB.UI.NewButton(Form)
BtnPlayNow.Caption = "Play &Now"
BtnPlayNow.Common.Height = bheight
BtnPlayNow.Common.Width = 70
BtnPlayNow.Common.Top = PosBar.Common.Top + PosBar.Common.Height +10
BtnPlayNow.Common.Left = midp -155
BtnPlayNow.UseScript = Script.ScriptPath
BtnPlayNow.ModalResult = 3
Dim BtnPlayNext : Set BtnPlayNext = SDB.UI.NewButton(Form)
BtnPlayNext.Caption = "Play N&ext"
BtnPlayNext.Common.Height = bheight
BtnPlayNext.Common.Width = 70
BtnPlayNext.Common.Top = BtnPlayNow.Common.Top
BtnPlayNext.Common.Left = midp -75
BtnPlayNext.UseScript = Script.ScriptPath
BtnPlayNext.ModalResult = 4
Dim BtnPlayLast : Set BtnPlayLast = SDB.UI.NewButton(Form)
BtnPlayLast.Caption = "Play &Last"
BtnPlayLast.Common.Height = bheight
BtnPlayLast.Common.Width = 70
BtnPlayLast.Common.Top = BtnPlayNow.Common.Top
BtnPlayLast.Common.Left = midp +5
BtnPlayLast.UseScript = Script.ScriptPath
BtnPlayLast.Default = True
BtnPlayLast.ModalResult = 1
Dim BtnCancel : Set BtnCancel = SDB.UI.NewButton(Form)
BtnCancel.Caption = "&Cancel"
BtnCancel.Common.Height = bheight
BtnCancel.Common.Width = 70
BtnCancel.Common.Left = midp +85
BtnCancel.Common.Top = BtnPlayLast.Common.Top
BtnCancel.UseScript = Script.ScriptPath
BtnCancel.Cancel = True
BtnCancel.ModalResult = 2
'show preview form
Form.Common.Height = BtnCancel.Common.Top + bheight +40
Dim Tmr : Set Tmr = SDB.CreateTimer(1000)
Call Script.RegisterEvent(Tmr,"OnTimer","UpdatePosBar")
Dim res : res = Form.ShowModal
Dim lst : lst = SDB.Player.PlaylistCount-1
Call Script.UnregisterEvents(Tmr)
Select Case res
Case 1 'play last
'do nothing
Case 2 'cancel
Call SDB.Player.PlaylistDelete(lst)
Case 3 'play now
If lst <> curi Then
Call SDB.Player.PlaylistMoveTrack(lst,curi)
End If
Case 4 'play next
If lst <> curi+1 Then
Call SDB.Player.PlaylistMoveTrack(lst,curi+1)
End If
End Select
'restore player status
If res <> 3 Then
SDB.Player.Stop
SDB.Player.CurrentSongIndex = curi
SDB.Player.PlaybackTime = curp-1000
If playing Then
SDB.Player.Play
End If
While SDB.Player.IsStartingPlayback
SDB.ProcessMessages
WEnd
If Not (UCase(Left(SDB.Player.CurrentSong.Path,4)) = "HTTP") Then
SDB.Player.PlaybackTime = curp-1000
End If
If paused Then
SDB.Player.Pause
End If
End If
'restore status of other scripts
If Regs.OpenKey("Auto Rating", True) Then
Regs.IntValue("os00") = autoratesongson
Regs.CloseKey
End If
If autodj Then
SDB.Player.isAutoDJ = True
End If
If Not (scrobbler = "") Then
SDB.IniFile.StringValue("ScrobblerDJ","Enabled") = scrobbler
End If
If Not (autoalbum = "") Then
SDB.IniFile.StringValue("AutoAlbumDJ","Enabled") = autoalbum
End If
If crossfade Then
SDB.Player.isCrossfade = True
End If
If ratesong Then
SDB.IniFile.BoolValue("RatePlayedSong", "Enabled") = True
End If
Else
Call SDB.MessageBox("Previewer - You can only preview one track at a time.", mtError, Array(mbOk))
End If
End Sub
Sub UpdatePosBar(PosTimer)
Dim PosBar : Set PosBar = SDB.Objects("PreviewerPosBar")
If SDB.Player.CurrentSongLength > 0 Then
ManualChange = False
PosBar.Value = (SDB.Player.PlayBackTime*1000)\SDB.Player.CurrentSongLength
ManualChange = True
End If
If SDB.Player.CurrentSongLength < SDB.Player.PlayBackTime+2000 Then
Dim wsh : Set wsh = CreateObject("WScript.Shell")
Call wsh.SendKeys("%C")
End If
End Sub
Sub playPause (ClickedBtn)
If SDB.Player.isPaused Then
ClickedBtn.Caption = "&Pause"
SDB.Player.Play
Exit Sub
End If
If SDB.Player.isPlaying Then
ClickedBtn.Caption = "&Play"
SDB.Player.Pause
Exit Sub
End If
End Sub
Sub seekB30 (ClickedBtn)
SDB.Player.PlaybackTime = SDB.Player.PlaybackTime - 30000
End Sub
Sub seekB05 (ClickedBtn)
SDB.Player.PlaybackTime = SDB.Player.PlaybackTime - 5000
End Sub
Sub seekF05 (ClickedBtn)
SDB.Player.PlaybackTime = SDB.Player.PlaybackTime + 5000
End Sub
Sub seekF30 (ClickedBtn)
SDB.Player.PlaybackTime = SDB.Player.PlaybackTime + 30000
End Sub
Sub OnSeek(PosBar)
If ManualChange = True Then
SDB.Player.PlayBackTime = (PosBar.Value*SDB.Player.CurrentSongLength)\1000
End If
End Sub
Sub Install()
Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
If Not (inif Is Nothing) Then
inif.StringValue("Previewer","Filename") = "Previewer.vbs"
inif.StringValue("Previewer","Procname") = "Previewer"
inif.StringValue("Previewer","Order") = "10"
inif.StringValue("Previewer","DisplayName") = "Previewer"
inif.StringValue("Previewer","Description") = "Preview a track without disturbing now playing"
inif.StringValue("Previewer","Language") = "VBScript"
inif.StringValue("Previewer","ScriptType") = "0"
SDB.RefreshScriptItems
End If
End Sub