I was searching around for the ProgID for Windows Media Player... borrowed some code from the OLE Browser's PerlScript (since my comp. won't run PerlScript), and searched the registry with its GUID to find its ProgID.
Then I discovered Microsoft already had all the info I needed in their help center thing.![[blush] [blush] [blush]](/data/assets/smilies/blush.gif)
Anyway, I've been playing around with it, trying to follow their docs ( )...
Some of the things they listed in their docs don't seem to work with Perl. For example, this is an object/method heirarchy in their API:
PlayerObject -> currentMedia -> name
This should be the name of the file currently playing. But I get a "can't call method 'name'" error, or a "use of uninitialized value" error, with the following codes respectively:
So first... here's the full content of my test code that I've been tinkering around with:
I know some bits of that code wouldn't run because of while loops or exits or whatever, this is my experimentation code that I've been jerry-rigging together while playing with this API
Now, one thing that the docs says, is that there's a
PlayerObj->PlayerApplication->switchToControl
which should "dock" the media player (I assume it means to attach it to your task bar or to just hide the GUI)
The docs say that this is for C++ only though... why is that? Or... can that be done in Perl?
In Perl, any reference to $player->playerApplication or $player->{playerApplication} causes weird "fatal exception" errors to print out to the console.
SO, on to the questions!
1) Does anybody know if the Windows Media Player API has a function to hide the GUI of the media player?
2) Does anybody know of a tutorial or something that outlines a good lot of the functions Perl can do to the WMPlayer API? Cuz all I figured out how to do is make it play files and mess with the CD-ROM drives.
Thanks.
Then I discovered Microsoft already had all the info I needed in their help center thing.
![[blush] [blush] [blush]](/data/assets/smilies/blush.gif)
Anyway, I've been playing around with it, trying to follow their docs ( )...
Some of the things they listed in their docs don't seem to work with Perl. For example, this is an object/method heirarchy in their API:
PlayerObject -> currentMedia -> name
This should be the name of the file currently playing. But I get a "can't call method 'name'" error, or a "use of uninitialized value" error, with the following codes respectively:
Code:
$player->currentMedia->name; # can't call method
$player->currentMedia->{name}; # uninit. value
So first... here's the full content of my test code that I've been tinkering around with:
Code:
#!/usr/bin/perl -w
use Config;
use Win32::OLE;
use Win32::OLE::Const;
use Win32::OLE::TypeInfo;
use Data::Dumper;
use Tie::File;
use threads;
$| = 1;
my @library = ();
my $player = Win32::OLE->new ('WMPlayer.OCX');
foreach my $key (keys %$player) {
print "$key\n\t = $player->{$key}\n";
}
print "\n========================\n\n";
# my $cds = $player->{cdromCollection};
# $Data::Dumper::Purity = 1;
# print Dumper($cds);
# for (0..$cds->{count}) {
# $cds->Item($_)->Eject() or next;
# }
$player->OpenPlayer ('[URL unfurl="true"]http://kirsle.rainbowboi.com/PKMNIP.mid');[/URL]
$player->{playerApplication}->{switchToControl} = 1; # doesn't work
print "Now Playing: " . $player->{currentMedia}->{sourceURL} . "\n"; # uninit value
sleep 3;
print Dumper $player->{currentMedia};
$player->{Settings}->{mute} = 1; # doesn't mute
exit;
my $t = threads->create (sub {
# This thread gets its own $player since
# I don't like threads::shared. -_-
my $player = Win32::OLE->new ('WMPlayer.OCX');
my $drive = '';
for (my $i = 0; $i < $player->cdromCollection->count; $i++) {
my $lab = $player->cdromCollection->item($i)->driveSpecifier;
$drive = $i unless length $drive;
print "CD Drive $i \"$lab\"\n";
}
while (1) {
my $label = $player->cdromCollection->item($drive)->driveSpecifier;
print "eject $label\n";
$player->cdromCollection->item($drive)->eject();
print "eject $label again...\n";
$player->cdromCollection->item($drive)->eject();
}
});
$t->detach;
while (1) {
print ".";
sleep 1;
}
$player->close(); # didn't close mplayer
# doesn't stop; no error: $control->Stop();
# doesn't play; no error: $control->Play();
I know some bits of that code wouldn't run because of while loops or exits or whatever, this is my experimentation code that I've been jerry-rigging together while playing with this API
Now, one thing that the docs says, is that there's a
PlayerObj->PlayerApplication->switchToControl
which should "dock" the media player (I assume it means to attach it to your task bar or to just hide the GUI)
The docs say that this is for C++ only though... why is that? Or... can that be done in Perl?
In Perl, any reference to $player->playerApplication or $player->{playerApplication} causes weird "fatal exception" errors to print out to the console.
SO, on to the questions!
1) Does anybody know if the Windows Media Player API has a function to hide the GUI of the media player?
2) Does anybody know of a tutorial or something that outlines a good lot of the functions Perl can do to the WMPlayer API? Cuz all I figured out how to do is make it play files and mess with the CD-ROM drives.
Thanks.