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. 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |