问题
I can see a similar question that has been answered here (How would i play a specific song in iTunes through java?) but it doesn't really answer my question (I don't think, anyway).
I have a couple of buttons on a winform (play, pause, skip forward, skip back) and want to be able to connect these through iTunes, so as to create a 'mini media player'.
However, I am having issues (obviously, or I wouldn't be writing this :P) with all this 'COM' malarkey. I have tried including (nearly) all the possible references from 'Apple', 'iTunes' and still can't seem to be able to find a way of pressing the button 'play' and actually playing a song in iTunes.
I have a button on click event (i've called the button btnPlay
). But does anyone know the 'correct' or 'efficient' way of connecting iTunes to winforms?
I've heard about something called sendKeys
, but I'm a total noob and have really no idea of how to create this sort of thing.
PS. I've also tried to find a refence for using iTunesLib;
(from http://blogs.msdn.com/b/noahc/archive/2006/07/06/automating-itunes-with-c-in-net.aspx) but this is a dated post, and i'm not certain this namespace is available anymore (well, I can't find it anywhere in the Com references
anyway.
As always, any help much appreciated.
回答1:
Add a reference to iTunes 1.xx Type Library (it will be in the COM list of references).
Then you can use iTunes app as so in your click event
iTunesApp app = new iTunesAppClass();
app.Play();
you will need to perform the following step to embed the the COM iTunes app.
Go to the Solution Explorer.
Right click on References –> iTunesLib and hit Properties.
Set “Embed Interop Types” to False.
来源:https://stackoverflow.com/questions/25605098/how-to-control-itunes-through-winforms