tags:

views:

112

answers:

2

It is possible to play/stop a youtube video(inside a web browser like FireFox), using external software(C#)?

A: 

Yes, but it is with JavaScript which you can handle with C#. You can hook into the YouTube API.

http://code.google.com/apis/youtube/overview.html

Dustin Laine
That not what I ment. I'm talking about a software(not website) that somehow send message to the web browser. The web browser is opened on some youtube.com video and my software will play/stop that video
Adir
could we know why you need such this ?
Space Cracker
A: 

I would assume this is not allowed by the YouTube Terms of Service, but I'm not sure. In any case, if this is more of a pet project or proof of concept here are some thoughts:

  • I doubt there are any existing libraries, etc... that can do this b/c of the TOS point.
  • You could probably build this on your own as so:
    • Load a page in a WebBrowser form control.
    • Once the page has loaded (DocumentCompleted event), search the DOM (browser.Document) for the video player element. You would probably look for a Flash element or some typically CSS class/id that YouTube always uses.
    • Get the screen position of that element. Not sure how to do this, maybe you can figure it out?
    • Simulate a mouse click (http://www.gamedev.net/community/forums/topic.asp?topic_id=321029) on the video player.

Once you have found the screen position, you only need to do the mouse click subsequent times. I like the above approach because you can more easily port it to other video sites if you need to - rather than relying on APIs.

I'm also curious why you want to do this. Could you let us in on your thoughts?

Chad
thank you Chad :) this is just for fun. sometimes I use youtube to hear music while I'm playing some game(full screen), so I tought it will be useful to use some kind of a keystroke to play or pause the music during the game without minimizing.
Adir
Ah! I feel your pain. What I do for external music while playing a full screen game is to use Winamp and it's Global Hotkeys (a default install option). Trouble, of course, is that you'll need to get your music on your computer. I think there are a good number of YouTube audio extractor plug-ins (e.g. https://addons.mozilla.org/en-US/firefox/addon/10544/ ) for FireFox. You could extract the audio and then play it in WinAmp in the background. Best of luck, let us know if you do roll your own app to do this. Thanks.
Chad