Foobar2000 Com Automation

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Foobar2000 Com Automation

30 Sep 2013, 07:06

First you need the COM server Component.
You can download it here and install it.
Here is a HUGE example. Most of the functions are here. (I left out the playlist functions)

Code: Select all

Foobar := ComObjCreate("Foobar2000.Application.0.7"),Foobar.Minimized := 1 ;Create the COM object and minimise foobar.
Playback := Foobar.Playback ;The playback handle.
Settings := Playback.Settings ;The settings handle.


MsgBox % Foobar.Name ; The Name and Version.
MsgBox % Foobar.ApplicationPath ;Where Foobar is installed.
MsgBox % Foobar.ProfilePath ;Where foobar settings are.

MsgBox % Playback.IsPlaying ;Returns if foobar is playing or not. -1 if playing, 0 if stopped. (STOPPED not Paused)
MsgBox % Playback.IsPaused ;Returns if playback is paused or not. -1 if paused, 0 if not.
MsgBox % Playback.CanSeek ;Returns if the playback can be seeked. 0 if it cannot be seeked. It's 0 in Radio stations.
Msgbox % Playback.FormatTitle("%title% - %album artist%") ; All of the title formatting is valid here. http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Title_Formatting_Reference

Playback.Pause() ;Pauses playback (Has a toggle effect.)
Playback.Next() ;Obvious right?
Playback.Previous() ;Self explanatory
Playback.Random() 
playback.Stop() ;This is NOT PAUSE, It's STOP. They are totally different!

MsgBox % Floor(Playback.Position) ;Display playback time.
MsgBox % Floor(Playback.Length) ;Display playback length.
MsgBox % Floor(Playback.Position) . "/" . Floor(Playback.Length) ;Display PlaybackTime/Length in Seconds.

Playback.Seek(3) ;Set seek onto the 3rd second.

Playback.SeekRelative(-5) ;Go back 5 seconds.
Playback.Seek(Playback.Position-5) ;Also goes back 5 seconds.
Playback.SeekRelative(+5) ;Skip 5 seconds ahead.
Playback.Seek(Playback.Position+5) ;Also Skips 5 seconds ahead.


MsgBox % Floor(100+Settings.Volume) 
;Gets the volume. In foobar, the volume is measured differently. If the volume was 99, in foobar it would show as -1. (99-100)
Settings.Volume := Settings.Volume+2 ;Increase the volume by 2 dBs(Most probably Decibals)
Settings.Volume := Settings.Volume-2 ;Decrease the volume.


MsgBox % Settings.CursorFollowsPlayback ;Displays the current, CursorFollowsPlayback Setting of foobar.
Settings.CursorFollowsPlayback := 0 ;Sets the option.
Settings.CursorFollowsPlayback := !Settings.CursorFollowsPlayback ;Toggle the Option.

MsgBox % Settings.PlaybackFollowsCursor ;Displays the current, PlaybackFollowsCursor setting.
Settings.PlaybackFollowsCursor := 0 ;Sets the option.
Settings.PlaybackFollowsCursor := !Settings.CursorFollowsPlayback ;Toggle the Option.

MsgBox % Settings.StopAfterCurrent ;Displays the StopAfterCurrent setting. It can be set,toggled the same way as the previous settings.


MsgBox % Settings.ActivePlaybackOrder ;Displays the current ActivePlaybackOrder. It will be one of these: Default, Repeat (playlist), Repeat (track), Random, Shuffle (tracks), Shuffle (albums), Shuffle (folders)
Settings.ActivePlaybackOrder := "Repeat (playlist)" ;It can be set.

PlaybackOrders:= Settings.PlaybackOrders
MsgBox % PlaybackOrders.Count() ;Displays number of playback orders.
For Order in PlaybackOrders ;Loop through all the orders.
	MsgBox %Order%


ComObjConnect(Playback,"Playback_") ;Connect playbacks events to the Playback_ prefix.
ComObjConnect(Settings,"Settings_")
return

;Playback Events.
Playback_Started(){
	MsgBox Playback Started.
}

Playback_Paused(newVal){
	;The parameter is the New "Playback.IsPlaying" value.
	If newVal
		MsgBox Playback was paused.
	else
		MsgBox Playback was Un-paused.
	return
}

Playback_Stopped(Reason){ ;Called in when stopped.
	Msg := (Reason = "0") ? ("(requested by user)") : ((Reason = "1") ? ("(end of file)") : ((Reason = "2") ? ("(starting another track)") : (Reason)))
	;If reason contains:
	;	1 -> Requested by User.
	;	2 -> End of File.
	;	3 -> Starting Another track.
	MsgBox Playback has stopped.`n%Msg%
}

Playback_TrackChanged(){ ;Called in when track has changed.
	global 
	Info := Playback.FormatTitle("%title% - %album artist%")
	Start := A_TickCount
	Loop,
		ToolTip,%Info%
	until A_Tickcount-Start >= 2000
	ToolTip,
	return
	Info := "",Start := ""
}

Playback_PositionChanged(Pos,Seeked){ ;Called in when the seek changes.
	Pos := Floor(Pos)
	If Seeked
		MsgBox Position changed by seeking. `nNew Pos:%Pos%
	;If Seeked=0 that means the song is playing.
}

;Settings Events.

Settings_CursorFollowsPlaybackChanged(newVal){
	Display(A_ThisFunc,newVal)
}

Settings_PlaybackFollowsCursorChanged(newVal){
	Display(A_ThisFunc,newVal)
}

Settings_StopAfterCurrentChanged(newVal){
	Display(A_ThisFunc,newVal)
}

Settings_ActivePlaybackOrderChanged(newVal){
	Display(A_ThisFunc,newVal)
}

Display(func,value){
	func := RegExReplace(SubStr(func,10),"([A-Z])"," $1")
	MsgBox Setting Changed:%func%`mNew Value:%value%
}
Last edited by Menixator on 24 May 2014, 09:47, edited 2 times in total.
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: Foobar2000 Com Automation

30 Sep 2013, 07:20

Many thanks, menixator,
I already figured out most of these (incl. events), but there seem to be some methods that I missed so far.
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Re: Foobar2000 Com Automation

30 Sep 2013, 07:33

I used the foobar2000.idl file that came with the Com server. :D
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: Foobar2000 Com Automation

30 Sep 2013, 07:46

I didn't even know what that is - an idl-file... but I probably looked at most of the other files...
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Re: Foobar2000 Com Automation

30 Sep 2013, 08:05

I don't know either. But all of the methods, events and stuff were in there.
Plus there was the VBS example which was quite similar to autohotkey and was really easy to follow.
User avatar
budRich
Posts: 82
Joined: 29 Sep 2013, 16:52
Location: Wermland
Contact:

Re: Foobar2000 Com Automation

30 Sep 2013, 18:46

Great! Thanks man.
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Re: Foobar2000 Com Automation

30 Sep 2013, 22:55

budRich wrote:Great! Thanks man.
You are welcome! ;)
alllala
Posts: 17
Joined: 03 Apr 2014, 05:04

Re: Foobar2000 Com Automation

21 May 2014, 09:11

Unfortunately you left out the the Playlist functions. I tried to get them to work with the foobar2000.idl but had no sucess until now.

Code: Select all

Foobar := ComObjCreate("Foobar2000.Application.0.7"),Foobar.Minimized := 1 ;Create the COM object and minimise foobar.
Playback := Foobar.Playback ;The playback handle.
Settings := Playback.Settings ;The settings handle.
Playlist := Foobar.Playlist
The last line was my humble try to acess the playlist functions of the library.

Why am I doing this?
I would like to Select the Playlist in Foobar with AHK even though I´m not sure right now, whether the Playlist function will give this opportunity. Anybody has an idea?
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Re: Foobar2000 Com Automation

23 May 2014, 07:31

Here. This will go through the usage of the playlist functions.

Code: Select all

Foobar := ComObjCreate("Foobar2000.Application.0.7")
Playlists := Foobar.Playlists

MsgBox % "You have " . Playlists.Count() . " playlists and you have a total number of " . Playlists.GetTracks().Count() . " track sin your library!"

/*
MsgBox Enumerating through all the songs in the playlist.
for song in Playlists.GetTracks()
{
	MsgBox % song.Path
	MsgBox  % song.Index
	MsgBox % song.FormatTitle("%artist% - %title%") ; The foobar title formatting works here.
}
*/
/*
MsgBox Enumerating through all the playlists.

for Playlist in Playlists
{
	index := Playlist.Index
	name := Playlist.name
	MsgBox Playlist:`n=========`nIndex: %index%`nname:%name%
	Playlist.DoDefaultAction(0) ; do the default action on the song with the provided index.
	songs := Playlist.GetTracks()
	for song in songs
	{
		MsgBox % song.Path
		MsgBox  % song.Index
		MsgBox % song.FormatTitle("%artist% - %title%") ; The foobar title formatting works here.
		; You can file a little help file in %ProgramFiles%/foobar2000/titleformat_help.html
	}
}
*/

MsgBox Adding a playlist with a name 'foo'.
p1 := Playlists.Add("foo")

MsgBox Renaming the added playlist to 'Renamed foo'
p1.Name := "Renamed foo"

MsgBox Activating the added playlist.
Playlists.ActivePlaylist := p1 ; activates the playlist

MsgBox Adding and activating a new playlist.
p2 := Playlists.Add("bar", true)

MsgBox Moving 'bar' to top.
;PositionFirst = 0
;PositionLast = 1
;PositionBefore = 2
;PositionAfter = 3
Playlists.Move(p2,0)
MsgBox Moving it to below foo.
Playlists.Move(p2,3,p1)
MsgBox Removing all added playlists.
Playlists.Remove(p1)
Playlists.Remove(p2)


/*
;Events

ComObjConnect(Playlists, "Playlists_")

Playlists_PlaylistAdded(index, playlistObj, name){
	Msgbox % "Added playlist at index " + (index + 1) + " with name """ + name + """"
}

Playlists_PlaylistRemoved(index, playlistObj){
	Msgbox % "Removed playlist at index " + (index + 1)
}

Playlists_PlaylistRenamed(index, playlistObj, newName){
	Msgbox % "Renamed playlist at index " + (index + 1) + " to """ + newName + """"
}

Playlists_PlaylistActivated(index, playlistObj){
	Msgbox % "Activated playlist at index " + (index + 1)
}

Playlists_PlaylistsReordered(first, last){
	Msgbox % "Reordered playlists between index " + (first+1) + " and index " + (last+1)
}
*/
td3zzz
Posts: 18
Joined: 15 Aug 2014, 20:53

Re: Foobar2000 Com Automation

18 Nov 2015, 09:11

mark.
Is there "msg" for foobar2000 ? i would like to use "PostMessage / SendMessage" , how did it work ?
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Foobar2000 Com Automation

18 Nov 2015, 23:53

This uses COM. You may try using WinMessages... However, I would not recommend it. :P
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
td3zzz
Posts: 18
Joined: 15 Aug 2014, 20:53

Re: Foobar2000 Com Automation

17 Jan 2016, 23:19

代码是有效的,不过你需要事先安装foobar2000的com server,作者一开始就提到了的。

“First you need the COM server Component.”
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: Foobar2000 Com Automation

17 Jan 2016, 23:57

“First you need the COM server Component.”
That's it. Find it on the foobar homepage and Install it (rather look at the link above in the first post of this thread). I think, development on it stopped long ago on alpha stage, but last time I checked (last year, I guess), it still worked with the newest foobar versions. But not sure... it seems 0.7 is still the latest version of this COM-object (no connection to the foobar version number!).
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Re: Foobar2000 Com Automation

07 Jan 2017, 11:13

If anyone is still wondering, this still works with the latest version of foobar.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Foobar2000 Com Automation

09 Jan 2017, 21:37

Good to see you're still alive :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Re: Foobar2000 Com Automation

28 Apr 2017, 15:05

joedf wrote:Good to see you're still alive :+1:
lol. Very dead here mate. I just check in every 6 months or so and whenever I get an email from the forum.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Foobar2000 Com Automation

10 May 2017, 10:41

haha, okay :3
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
asdsk9skdsdas
Posts: 36
Joined: 10 Mar 2019, 21:52

Re: Foobar2000 Com Automation

18 Nov 2020, 13:55

Is there a function to hide foobar to the system tray?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: metallizer and 114 guests