Back Button 1.0 [MM2]

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

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

Back Button 1.0 [MM2]

Post by trixmoto »

This script remembers previously played tracks so you can skip back even when in shuffle mode.

Code: Select all

'
' MediaMonkey Script
'
' NAME: BackButton 1.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 28/02/2006 
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'          Set the Capacity variable to the value you require
'
' [BackButton]
' FileName=BackButton.vbs
' ProcName=BackButton
' Order=31
' DisplayName=Back Button
' Description=Back Button
' Language=VBScript
' ScriptType=0
' [BackButton2]
' FileName=BackButton.vbs
' ProcName=BackButton2
' Order=31
' DisplayName=Back Button 2
' Description=Back Button 2
' Language=VBScript
' ScriptType=2
'

Option Explicit 
Dim Capacity

Capacity = 10  ' number of tracks to remember

Sub BackButton
  'check there is a memory
  Dim str,pos
  str = SDB.IniFile.StringValue("Scripts","BackButtonMemory")
  If str = "" Then
    pos = SDB.MessageBox("Sorry, there are no tracks in the memory to go back to.",mtInformation,Array(mbOk))  
    Exit Sub
  End If
    
  'check memory contains current track
  str = Left(str,Len(str)-1)
  pos = InStrRev(str,"|")
  If pos < 2 Then
    pos = SDB.MessageBox("Sorry, there are no tracks in the memory to go back to.",mtInformation,Array(mbOk))  
    Exit Sub
  End If

  'check memory contains previous track
  str = Left(str,pos-1)
  pos = InStrRev(str,"|")
  If pos = 0 Then
    pos = SDB.MessageBox("Sorry, there are no tracks in the memory to go back to.",mtInformation,Array(mbOk))  
    Exit Sub
  End If

  'extract previous track from memory
  Dim trk
  trk = Int(Mid(str,pos+1))
  str = Left(str,pos)
    
  'find last track   
  Dim found
  found = False
  If SDB.Player.CurrentSong.ID = trk Then 
    'play if currently now playing
    found = True
  Else
    'play if in now playing list
    Dim list,itm,i
    Set list = SDB.Player.CurrentSongList
    For i = 0 To list.Count-1
      Set itm = list.Item(i)
      If itm.ID = trk Then 
        SDB.Player.CurrentSongIndex = CLng(i)
        found = True
        Exit For
      End If
    Next  
    'else add to now playing
    If not found Then 
      Dim sql,iter      
      sql = "AND (Songs.ID="&trk&")"
      Set iter = SDB.Database.QuerySongs(sql)
      If Not iter.EOF Then 
        SDB.Player.PlaylistAddTrack(iter.Item)
        SDB.Player.CurrentSongIndex = list.Count
        found = True
      End If
    End If      
  End If
    
  'play and update memory
  If found Then
    SDB.IniFile.StringValue("Scripts","BackButtonMemory") = str
  Else
    pos = SDB.MessageBox("Sorry, the previous track could not be found.",mtInformation,Array(mbOk))
  End If
End Sub

Sub BackButton2
  'add track to memory
  Dim str,arr,trk,max,tmp
  trk = SDB.Player.CurrentSong.ID
  str = SDB.IniFile.StringValue("Scripts","BackButtonMemory")
  If str = "" Then
    str = "|"&trk&"|"
  Else
    tmp = str
    str = str&trk
    arr = Split(Mid(str,2),"|")
    max = UBound(arr)
    If arr(max-1) = arr(max) Then
      str = tmp
    Else
      If max >= Capacity Then 
        str = Mid(str,InStr(2,str,"|"))
      End If
      str = str&"|"
    End If
  End If
  SDB.IniFile.StringValue("Scripts","BackButtonMemory") = str
End Sub
Last edited by trixmoto on Fri Nov 30, 2007 3:45 am, 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.
onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

Why don't you only look at Table "Played" which Song was played last (or Table "Songs" Field "LastTimePlayed")? :wink:
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

You could use the database but I couldn't remember how they were updated. I thought they weren't updated until you were a third of the way through the track or something. Or is that just the playcounter?
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.
onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

I don't know, but if you're right then your way might be better.
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx
psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova »

trixmoto wrote:You could use the database but I couldn't remember how they were updated. I thought they weren't updated until you were a third of the way through the track or something. Or is that just the playcounter?
Trix is right, the 1/3 of the song must be played to be entered in the "Played" table
Guest

Post by Guest »

@trixmoto:
Real nice plugin, thanks for it. It is how the Back Button should behave... :roll:

By the way, is there a way to change the "back button" behavior so that it behaves as this plugin?
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

No this is not possible. By the devs have said they'll look into the behaviour, so it might be fixed in a future version.
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.
Guest

Post by Guest »

:D Great!!!

Thanks for the info and -- once again -- for the plugin. :wink:
Guest

Post by Guest »

Anonymous wrote:(...) for the plugin (...)
err... I mean for the script. :roll:
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Zachm019 wrote:WOW Thanks a TON trixmoto!!! Do you happen to know if there is a way to create a short cut for that script? I got it installed and working just wondering if there was a way I could press a key combination for it to work... now on the sad note while I was typing it this message it went forward to another song and I got two error messages...

Image
Image

Do you know what is causing this?
Originally posted here: http://www.mediamonkey.com/forum/viewto ... 2448#52448
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 »

In the "{MM}\Scripts\Scripts.ini" file you will find the following entries...

Code: Select all

[BackButton]
FileName=BackButton.vbs
ProcName=BackButton
Order=31
DisplayName=Back Button
Description=Back Button
Language=VBScript
ScriptType=0

[BackButton2]
FileName=BackButton.vbs
ProcName=BackButton2
Order=31
DisplayName=Back Button 2
Description=Back Button 2
Language=VBScript
ScriptType=2
That blank line might not be there, but it is in this space (directly before "[BackButton2]") that you will want to add the following line...

Code: Select all

Shortcut=Ctrl+Shift+B
Or whatever shortcut key combination you want!

About the error: There is a variable at the top of the BackButton.vbs file called "Capacity" which by default is 10. Have you changed this? If so, what to?

If you could open "{MM}\MediaMonkey.ini" in a text editor and find the [Scripts] secction and tell me the value of "BackButtonMemory" - that might also be useful.
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.
Zachm019
Posts: 54
Joined: Sat Jun 24, 2006 11:21 pm
Contact:

Post by Zachm019 »

I have recopied your code as said... in the script.ini and the BackButton.vbs. Without changing anything but adding the shortcut information in the blank line and I still get the error message
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Could you please open "{MM}\MediaMonkey.ini" in a text editor and find the [Scripts] secction and tell me the value of "BackButtonMemory" - this is probably the root of the problem.
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.
Zachm019
Posts: 54
Joined: Sat Jun 24, 2006 11:21 pm
Contact:

Post by Zachm019 »

in the mediamonkey.ini this is all that is there

[out_ds]
cfg_total_time=36539093
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Then you're looking at the wrong .ini file. Try the one in "..\My Documents\My Music\MediaMonkey\".
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.
Post Reply