Previewer 2.9 - Updated 26/07/2014

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Previewer 2.9 - Updated 26/07/2014

Post by trixmoto »

This script previews a song. If you are playing a song (or have one paused) it remembers this song and position. It then adds the selected song to the end of your now playing list (remembering where it added it) and plays it. When the song has finished, it removes it from your now playing list, and plays the previous song from where it left off. Genius! One limitation is that if the interrupted track is a stream then the position cannot be restored, so it will restart from the beginning.

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
Last edited by trixmoto on Mon Apr 28, 2008 4:34 pm, edited 14 times in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy »

please explain the use for this script trixmoto because i am lost?

i just play the song and click on the next song and so on and so fourth when i want to preview songs.

what does this script do for me that i should use it? i really am not trying to be sarcastic i am lost as to why this is here?

:o
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Sorry I should have posted this link: http://www.mediamonkey.com/forum/viewtopic.php?t=6589. This is where the idea came from.

The script should allow you to preview a song without affecting your Now Playing list, so it stops what you're currently listening to, and then continues from that point after you've previewed the song you wanted to. The script is currently in it's very early stages though! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Ok, this new version (2.0) has a form ("mini player") which opens up to allow you to control your preview. Thanks very much to psyxonova who has been helping with this project.

:o New version below :o
Last edited by trixmoto on Thu Jun 29, 2006 6:55 pm, edited 1 time in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
slyr

works good

Post by slyr »

works great, maybe you could add a short cut crt + something,
to make it even easier to preview !!

this is realy usefull when creating a playlist,

thanks alot
slyr

Post by slyr »

i tried to add shortcut in the ini file (i'm very optimistic :-? ) , but i didn't work. :(
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Your INI entry should look like this if you want a shortcut:

Code: Select all

[Previewer]
FileName=Previewer.vbs
ProcName=Previewer
Order=10
DisplayName=&Previewer
Description=Preview a track without disturbing now playing
Language=VBScript
ScriptType=0
Shortcut=Shift+Alt+P
(Obviously you can use any shortcut you want, this is the one I use!) :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
slyr

works great

Post by slyr »

ok thanks alot

i think i had put it between " " , but now it works. :D
thanks alot for the fast assistance and a great script.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Glad you like the script. With a little help from psyxonova there should be an improved and more stable version coming out soon. :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Bandolero
Posts: 26
Joined: Mon Mar 28, 2005 4:21 am
Location: New York City

shortcut

Post by Bandolero »

Thanks for this great script. I've been trying to do this for a while.

I use Alt+Q for a shortcut and it works great.
powerpill-pacman
Posts: 154
Joined: Mon Feb 21, 2005 1:07 pm
Location: berlin, germany
Contact:

Post by powerpill-pacman »

This script is absolutely great, didn't even think that this would be possible. Thank you so much. :D
Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby »

Excellent script Trixmoto. One of the neatest I have come across. Well done.

I can see opportunities for further enhancements - like selecting next and previous songs to also preview - skipping quickly thru a list without leaving the script.

I am sure with more use I will think of more.
Regards
Philby
Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby »

Didnt take long !

How about also a progress bar to show whereabouts you are in the song ?
This would complement the forward and backward movement by time buttons.
Regards
Philby
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

New version (2.1) is now available from my website.

Thanks to MoDementia who added check/disable/re-enable for AutoDJ and AutoRateSongs.

I've just seen some of your suggestions which I'd forgotten so I will implement some of these soon.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
MoDementia
Posts: 1321
Joined: Thu Jun 15, 2006 3:26 pm
Location: Geelong, Victoria, Australia

Post by MoDementia »

Philby wrote:Excellent script Trixmoto. One of the neatest I have come across. Well done.

I can see opportunities for further enhancements - like selecting next and previous songs to also preview - skipping quickly thru a list without leaving the script.
I didn't see this thread before (just browsed your website) but I agree with Philby :)

I did have in mind to add his enhancement later but I'm sure you could do it alot faster/better :wink:
Post Reply