Sunday, November 13, 2005

Pandora VB/VS 2005 "Minimize to System Tray" Player

Since I read about Pandora, I’ve been listening to it non-stop. But as I mentioned before, it bugs me that I can't minimize it to the system tray.

Finally I stopped obsessing about it (Who me? Obsessing about something? Na…  ;)  and I took a few minutes and built my own VB/VS 2005 host for it, using the updated WebBrowser and NotifyIcon controls.

Now I have a Pandora Player that I can minimize to my system tray! Yeah. Instead of being hosted in IE, it's just hosted in the new WebBrowser control… No hacking, content removal, etc, etc.

It’s very easy to do…

  1. Create a new VB project

  2. Add a WebBrowser control to the form

  3. Dock the control to the Parent (i.e. Docking = Fill)

  4. Add a NotifyIcon to the form

  5. On the NotifyIcon SmartTag, select “Choose Icon” and pick a icon somewhere on your system.

  6. Paste in the below code to the form.

  7. You’re done! You now have System Tray Pandora Player.. Yeah!


Public Class Form1

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    WebBrowser1.Navigate("http://www.pandora.com/?cmd=tuner")
  End Sub

  Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
    Me.Show()
    Me.WindowState = FormWindowState.Normal
    NotifyIcon1.Visible = False

  End Sub

  Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize

    If Me.WindowState = FormWindowState.Minimized Then
      NotifyIcon1.Visible = True
      Me.Hide()
    End If

  End Sub

End Class


Update #1 11/13/2005 @ 2:14 PM (PST):
There's one thing that is a little weird...

The Flash player does not respond to clicks unless you first click on the hosting web page. For each click you want to make on the Flash app, you must first click on the web page and then the Flash app...

So if you want to pause the playing, click on the web page area above the player and then click on the pause button... If you want to say "I Like it" on a song, click on the page, the song (to get the song menu), the page again and then finally on the "I Like It" menu item.

Yeah it's kind of a pain but for me its worth it to have a SysTray player... Your milage may vary, yada, yada, yada...

8 comments:

Anonymous said...

Did you find a way to load the page in your application in Minimize mode?

Greg said...

Solve the weird "click the page then click the Flash control" thing that I talked about in Update #1?

Nope, not yet... But I havn'r really tried hard either. I still use the app (pretty much every day) and the issue isn't that big of one so I live with with for now.

I am thinking that to solve this I might need to move beyond the WebBrowser control and directly host IE on the page (http://coolthingoftheday.blogspot.com/2006/03/extending-net-20-webbrowser-control.html)

Anonymous said...

Seems lovely, but way too technical for me. If it's not a Firefox xpi or Google/Opera widget I'm lost! Gotta love the Pandora though!

Anonymous said...

You can also use the Microsoft Web Browser COM object to get around the Flash clicking problem.

I compiled a C# version and threw it up on my site.

Download here: http://www.silassewell.com/blog/article.php?article=3

Greg said...

Great tip, thank you.

With a quick tweak, my PandoraPlayer is using the Microsoft Web Broswer COM control and now the Flash click issue is resolved.

Less than two minutes of work and an irritating problem is resolved... Now that's a tip! :)

Thanks again...

Anonymous said...

http://silassewell.googlepages.com/pandora

Anonymous said...

Try this app at http://openpandora.googlepages.com/

Greg said...

Some of the things that the OpenPandora project does looks pretty interesting. Thanks...