473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Playability of a file in windows media player

Basically,
I want to check if a URL is playable or not (without actually playing
it).
i.e. given a URL I want to write an automation script to figure it out
for me
if it's playable or not. If you give a bad/invalid URL for windows
media
player to play a pop-up window shows us that it cannot be played. So
I would want to catch that event.

I have found 2 ways to do this -

1)

import win32com.client, win32api, sre, time

data = file("webclips.txt")
web_clips = data.readlines ()

shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("wmplayer.exe")
shell.AppActivate("Windows Media Player")
win32api.Sleep(100)

print "Total :", len(web_clips)

for webclip in web_clips:
shell.SendKeys("^u", 0)
shell.AppActivate("Open URL")

shell.SendKeys("{DEL}")
shell.SendKeys(webclip)
shell.SendKeys("~")
time.sleep(25)

if shell.AppActivate("Windows Media Player"):
webclip = webclip
not_there.append(webclip)
shell.SendKeys("~")

print len(not_there)
print "Not here: ", not_there
~

In this way I manually fire Windows media player and do the checking.
But It's a brute force way of solving the problem (since for every URL
I keep a
time-out of 25 seconds). As a result it takes a lot of time.I had to
look for a
better solution. My second solution uses Windows much hyped ActiveX
controls.

2)

from win32com.client import Dispatch,DispatchWithEvents

class WMPEvents:
def OnVisible(self,evt):
print "OnVisible changed:",evt
def OnError(self,evt=None):
print "OnError",evt
def OnMediaError(self,evt=None):
print "OnMediaError",evt
def OnDisconnect(self,evt):
print "OnDisconnect",evt
def OnStatusChange(self):
print "OnStatusChange"
def OnDisconnect(self,evt):
print "Disconnect",evt
def OnBuffering(self,evt):
print "OnBuffering changed:",evt
def OnOpenStateChange(self,evt=None):
print "OnOpenStateChange" ,evt

mp = DispatchWithEvents("WMPlayer.OCX", WMPEvents)
mp.settings.autoStart = True
webclip_playlist = mp.newPlaylist('Web_Clips', "")

raw_web_clips = []
data = file("webclips.txt")
web_clips = data.readlines()

for url in web_clips:
tune = mp.newMedia(url)
mp.currentPlaylist.appendItem(tune)
mp.controls.playItem (tune)
mp.controls.play()
mp.controls.stop()

raw_input("Press enter to stop playing")
mp.controls.stop()
mp.close()

This solution is much faster. But still I'm not able to solve it.
Initially I had
planned to use the "OnOpenStateChange" event to detect if a given URL
is in
a state just about to be opened. That's good enough for me to declare
that a
URL can be played. But as written in MSDN, they suggest not to rely on
state
changes as a definitive way to find details. So, I had to find an
alternative.
There is an event called "OnBuffering", i.e. when a link is found and
is just
about to be buffered this event (Boolean value) is triggered. But it
never seem
to happen.

I would be truly grateful if you can help in any way.

May 3 '06 #1
1 5495
The below code will catch the OnError event that's
triggered when you specify a bad URL.

import win32com.client
class wmpevents:
def OnOpenStateChange(self, NewState):
"""Sent when the control changes OpenState"""
print 'OnOpenStateChange', NewState
if NewState==win32com.client.constants.wmposMediaOpen :
print "Media successfully opened"
def OnError(self):
"""Sent when the control has an error condition"""
print 'OnError'
print self.Error.Item(0).errorCode, self.Error.Item(0).errorDescription
self.Error.clearErrorQueue()

win32com.client.gencache.EnsureDispatch('WMPlayer. OCX',0)
w=win32com.client.DispatchWithEvents('WMPlayer.OCX ', wmpevents)
w.URL='some bad URL'

Roger

"sri2097" <sr********@gmail.com> wrote in message news:11**********************@j73g2000cwa.googlegr oups.com...
Basically,
I want to check if a URL is playable or not (without actually playing
it).
i.e. given a URL I want to write an automation script to figure it out
for me
if it's playable or not. If you give a bad/invalid URL for windows
media
player to play a pop-up window shows us that it cannot be played. So
I would want to catch that event.

I have found 2 ways to do this -

1)

import win32com.client, win32api, sre, time

data = file("webclips.txt")
web_clips = data.readlines ()

shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("wmplayer.exe")
shell.AppActivate("Windows Media Player")
win32api.Sleep(100)

print "Total :", len(web_clips)

for webclip in web_clips:
shell.SendKeys("^u", 0)
shell.AppActivate("Open URL")

shell.SendKeys("{DEL}")
shell.SendKeys(webclip)
shell.SendKeys("~")
time.sleep(25)

if shell.AppActivate("Windows Media Player"):
webclip = webclip
not_there.append(webclip)
shell.SendKeys("~")

print len(not_there)
print "Not here: ", not_there
~

In this way I manually fire Windows media player and do the checking.
But It's a brute force way of solving the problem (since for every URL
I keep a
time-out of 25 seconds). As a result it takes a lot of time.I had to
look for a
better solution. My second solution uses Windows much hyped ActiveX
controls.

2)

from win32com.client import Dispatch,DispatchWithEvents

class WMPEvents:
def OnVisible(self,evt):
print "OnVisible changed:",evt
def OnError(self,evt=None):
print "OnError",evt
def OnMediaError(self,evt=None):
print "OnMediaError",evt
def OnDisconnect(self,evt):
print "OnDisconnect",evt
def OnStatusChange(self):
print "OnStatusChange"
def OnDisconnect(self,evt):
print "Disconnect",evt
def OnBuffering(self,evt):
print "OnBuffering changed:",evt
def OnOpenStateChange(self,evt=None):
print "OnOpenStateChange" ,evt

mp = DispatchWithEvents("WMPlayer.OCX", WMPEvents)
mp.settings.autoStart = True
webclip_playlist = mp.newPlaylist('Web_Clips', "")

raw_web_clips = []
data = file("webclips.txt")
web_clips = data.readlines()

for url in web_clips:
tune = mp.newMedia(url)
mp.currentPlaylist.appendItem(tune)
mp.controls.playItem (tune)
mp.controls.play()
mp.controls.stop()

raw_input("Press enter to stop playing")
mp.controls.stop()
mp.close()

This solution is much faster. But still I'm not able to solve it.
Initially I had
planned to use the "OnOpenStateChange" event to detect if a given URL
is in
a state just about to be opened. That's good enough for me to declare
that a
URL can be played. But as written in MSDN, they suggest not to rely on
state
changes as a definitive way to find details. So, I had to find an
alternative.
There is an event called "OnBuffering", i.e. when a link is found and
is just
about to be buffered this event (Boolean value) is triggered. But it
never seem
to happen.

I would be truly grateful if you can help in any way.

May 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anise | last post by:
I have a question concerning embedding a windows media player into a web application in .net.. I download Windows Media Player 10 and its SDK On the .ascx page I placed a windows media player...
1
by: Stephen Adam | last post by:
Hi there, Have spent a while trying to find out how to connect to Windows Media Player through COM. Unfortunately there doesnt seem to be much stuff about it on the web. What I need to do is...
0
by: icho | last post by:
Hi, I got a windows media player in an aspx page, which accesses files from a network share. I've maintain a connection using WNetAddConnection2 method of the windows API, but somehow the...
3
by: felecha | last post by:
I can get Windows Media Player to start, and play a wav file just fine using a command line "C:\Program Files\Windows Media Player\wmplayer.exe" c:\Temp\temp.wav But I want it to come up from...
7
by: Bob | last post by:
I have a media file Myfile.wme that I want to play within the Windows default media player on a button or menu click event in my app. The file is in a folder relative to my bin folder. I can...
9
by: Morris Neuman | last post by:
Im working with VS 2005 and trying to use a Hyperlink field in a datagrid to play a wave file that is not located in the website folders but is in a plain folder on the same machine, windows 2003...
2
by: Garrett | last post by:
I'm writing a small program in C# that will sit in the system tray and "monitor" Windows Media Player. I want the program to grab the file name (and checksum) of whatever video a user is playing in...
0
by: artsohc | last post by:
Hey Everyone, this is my first time posting so go easy on me. I am trying to hook up music-on-hold at the office I work at. I got all the music loaded and I got Windows Media Player working while...
6
by: Johnny J. | last post by:
Can anybody get me started on how to play an FLV file? Like you play e.g. mpeg files using the wmplayer control, I want a box on my form where the FLV is played and the playback is controlled byt...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.