Mp3 Player

By Ghost-lit Warder on Aug 12, 2007

A simple Mp3 player I have been working while taking on other script projects. This is still in its Beta stage so any comments or suggestions would be extremely appreciated.

Use: Type /mp3 -> Choose: button

alias mp3.length { 
  var %mp3.len $int($calc($1 / 1000))
  var %mp3.min $int($calc(%mp3.len / 60))
  var %mp3.sec $calc(%mp3.len - (%mp3.min * 60))
  if (%mp3.min < 10) { set %mp3.min 0 $+ %mp3.min }
  if (%mp3.sec < 10) { set %mp3.sec 0 $+ %mp3.sec }
  set %mp3.len %mp3.min $+: $+ %mp3.sec
  return %mp3.len
}
alias mp3.entry {
  var %mp3.entry
  if (.wav isin $longfn($1)) {
    set %mp3.entry $nopath($longfn($1))
    set %mp3.entry $remove(%mp3.entry,.,wav)
    set %mp3.entry %mp3.entry - WAVE File
    return %mp3.entry
  }
  if (.mid isin $longfn($1)) {
    set %mp3.entry $nopath($longfn($1))
    set %mp3.entry $remove(%mp3.entry,.,mid)
    set %mp3.entry %mp3.entry - MIDI File
    return %mp3.entry
  }
  if (.mp3 isin $1) {
    set %mp3.entry $mp3($1).artist - $mp3($1).title
  } 
  if (.mp3 isin $1) && ($mp3($1).artist == $null) || ($mp3($1).title == $null) {
    set %mp3.entry $remove($nopath($longfn($1)),.mp3)
  }
  return %mp3.entry
}
alias mp3.play {
  if (!$dialog(mp3)) { return }
  if (%mp3.pause == 1) { goto proceed }
  .timermp3 off
  if ($1) || ($exists($1)) {
    set %mp3.file $1
    goto playfile
  }
  if (!%mp3.file) { return }
  :playfile
  if (.mp3 !isin %mp3.file) { did -b mp3 5,9 }
  else { did -e mp3 5,9 }
  splay %mp3.file
  unset %mp3.pause
  .timermp3 0 1 mp3.position
  did -ra mp3 2 $mp3.entry(%mp3.file)
  did -ra mp3 3 00:00 / $gmt($mp3.length($mp3(%mp3.file).length),nn:ss)
  return
  :proceed
  splay resume
  did -e mp3 7
  set %mp3.pause 0
  .timermp3 0 1 mp3.position
  did -ra mp3 4 $sound($insong).album
}
alias mp3.eject {
  set %mp3.file $file="Please Select A Media File ..." "C:\*.*" 
  if (!%mp3.file) { return }
  set %mp3.file $shortfn(%mp3.file)
  if ($dialog(mp3)) {
    did -ra mp3 2 $mp3.entry(%mp3.file)
    did -ra mp3 3 00:00 / $mp3.length($mp3(%mp3.file).length)
  }
  return %mp3.file
}
alias mp3.stop { 
  .timermp3 off
  splay -p stop
  splay -w stop
  splay -m stop
  unset %mp3.pause
  did -ra mp3 3 $mp3.length($inmp3.pos) / $mp3.length($mp3(%mp3.file).length)
}
alias mp3.pause { 
  if (!$inmp3) { return }
  splay pause
  set %mp3.pause 1
  .timermp3 off
  did -b mp3 7
}
alias mp3.seek {
  if (!$inmp3) || (!$1) || (!$dialog(mp3)) { return }
  var %mp3.sfactor 10
  if ($1 = back) {
    var %mp3.seek $calc($inmp3.pos - (%mp3.sfactor * 1000))
    if (%mp3.seek < 0) { return }
    goto seek
  }
  if ($1 = skip) {
    var %mp3.seek $calc($inmp3.pos + (%mp3.sfactor * 1000))
    if (%mp3.seek > $inmp3.length) { return }
    goto seek
  }
  :seek
  splay seek %mp3.seek
  did -ra mp3 3 $gmt($mp3.length($inmp3.pos),nn:ss) / $gmt($mp3.length($mp3(%mp3.file).length),nn:ss)
  return
}
alias mp3.position { if ($dialog(mp3)) did -ra mp3 3 $gmt($mp3.length($inmp3.pos),nn:ss) / $gmt($mp3.length($mp3(%mp3.file).length),nn:ss) }
dialog mp3 {
  title "Mp3 player"
  size -1 -1 127 39
  option dbu
  box "", 1, -3 -3 300 4
  text "", 2, 3 4 150 7
  text "", 3, 84 14 39 8
  button "<|", 5, 3 25 12 11
  button "||>", 6, 17 25 12 11
  button "||", 7, 31 25 12 11
  button "[[]]", 8, 45 25 12 11
  button "|>", 9, 59 25 12 11
  button "Choose:", 10, 73 25 25 11
  check "Repeat", 11, 100 25 24 11, push
  button "", 12, 0 0 0 0, cancel
  text "", 4, 3 14 70 8
}

alias mp3 { if (!$dialog(mp3)l) dialog -md mp3 mp3 }
On *:DIALOG:mp3:init:0:{
  if (%mp3.file) { did -ra mp3 2 $mp3.entry(%mp3.file) }
}

On *:DIALOG:mp3:sclick:5:{ mp3.seek back }
On *:DIALOG:mp3:sclick:6:{ mp3.play }
On *:DIALOG:mp3:sclick:7:{ mp3.pause }
On *:DIALOG:mp3:sclick:8:{ mp3.stop }
On *:DIALOG:mp3:sclick:9:{ mp3.seek skip }
On *:DIALOG:mp3:sclick:10:{ .timer 1 0 mp3.eject }
On *:DIALOG:mp3:sclick:12:{ splay stop }
On *:MP3END:{ if ($dialog(mp3)) && ($did(mp3,11).state == 1) { mp3.play } }
On *:WAVEEND:{ if ($dialog(mp3)) && ($did(mp3,11).state == 1) { mp3.play } }
On *:MIDIEND:{ if ($dialog(mp3)) && ($did(mp3,11).state == 1) { mp3.play } }

Comments

Sign in to comment.
Akishoot   -  Sep 24, 2007

@ fusion2000 - Type /mp3 to open the dialog. Click on the \'Choose:\' button on the dialog to find a song. Then press the play button. :)

 Respond  
Akishoot   -  Sep 24, 2007

Under the alias mp3.length you should fix this line:

  set %mp3.len %mp3.min $+: $+ %mp3.sec

To:

  set %mp3.len %mp3.min $+ : $+ %mp3.sec

The $+ touching the : is causing the numbers to come out like: 0132, when you first Choose a song. Other then that it\'s a decent player. =)

 Respond  
fusion2000   -  Sep 22, 2007

I\'m new to this so don\'t make funn of me >.>

How do i add songs to it???

 Respond  
Scakk   -  Sep 05, 2007

Perhaps add a button that can let you delete or add certain songs instead of your entire music directory. I have over 1700 songs.

 Respond  
Ghost-lit Warder   -  Sep 04, 2007

Everything seems to be working fine.. I\'ve tried it with multiple circumstances and everything performed as expected.. I fixed the error of the /player.

 Respond  
Ghost-lit Warder   -  Sep 04, 2007

Alright, I\'ll work on the bugs and most likely redesign the dialog. I will add the option to seek as well. Thank you Lindrian.

 Respond  
Lindrian   -  Sep 04, 2007

uh, its has shit loads of bugs.
And it needs lots and lots of improvements... Try using a few more functions, use -b/e switches to disable and enable functions.
The pause function acually stops the song, and doesnt play.
There\'s no really seek function, imho, its a good starter, but not even close to good, sorry buddy.
Also, /player returns an error if the dialog is already open, use $iif.

 Respond  
guest598594   -  Sep 04, 2007

i love it, great job

 Respond  
Ghost-lit Warder   -  Sep 04, 2007

Thank you Zsadist.

 Respond  
Zsadist   -  Sep 04, 2007

Dude. this script is extremly good. If I choose to be lazy and just flood the forum, I am so giving this a high rating.

 Respond  
Ghost-lit Warder   -  Aug 28, 2007

When you choose a song and it plays a different one, is it always that one? That would be caused by a $did(10,mp3) mistake in the playlist as an example. It should work, if you haven\'t edited the $did. ;x

 Respond  
Storm2108   -  Aug 22, 2007

Well when i pick a song it plays a completely different song then i picked.

 Respond  
Ghost-lit Warder   -  Aug 13, 2007

Any comments or suggestions?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.