Zope Dynamic Videos HowTo |
Created by fowlertrainer . Last modified 2004-04-30 04:40:29. |
How to we embedding video clip into page from dynamic source ? |
Sometimes we need to use dynamic videos in our site. But how to we do it ?First: if you don't know, how to use dynamic content creation, you must read the Dynamic Images Howto. When you finished with this HowTo above, you know the basics of the content type settings, and dynamic data handling. So we can do that:
## Script (Python) "getdynavideo"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
request=context.REQUEST
RESPONSE=request.RESPONSE
RESPONSE.setHeader('Content-Type','video/mpeg')
id=request['vid']
rows=context.video_sql(sql="select VIDEO_BLOB from MEDIAS where vid=%s"%str(id))
if len(rows)==0: return None
data=rows[0]['VIDEO_BLOB']
return data
Usage of this script: <a border="0" tal:attributes="href python:'/getdynavideo?vid='+str(videoid)"> Dowload the movie here...</a> Ok, it is good. But how to we embedding this video into the page ?The video is not includable, as picture with img tag. So we need the "embed" tag to embedding a video into the page See that: <embed src="/dynavideo.mpeg" type="application/x-mplayer2" width="320" height="286" name="MediaPlayer"/> Well, that's great. It is useable, and it is working. We can change the source of the video like this: <embed type="application/x-mplayer2" width="320" height="286" name="MediaPlayer" tal:attributes=" src python:'/dynavideo?vid'+str(videoid)"/> When you try the example above, you see that is not working... Why ? You ask. See below. Windows Media Player Sucks - the extension mania !When you copy the source of the video, and paste it to your browser as url, the browser is show the "Download or Open" dialog, and you can download the video file data. When you download it, and save as "test.mpeg", you can open, and play it with Windows Media Player. Then what is the problem with "embed" tag ? When the QuickTime player, and plugins are installed in your system, and you modify the code (remove some tags), you see, that the "embed" tag is working. Try this: <embed type="video/mpeg" width="320" height="286" name="MediaPlayer" tal:attributes="src python:'/dynavideo?vid'+str(videoid)"/> As you see, the QuickTime is can playing this video ! The solution is the extension: the Windows Media Player is developed as filesystem based application first, and URL handling is added later to it's code. This caused that Windows Media Player is need the extension of the file ! QuickTime player is working good, because it is don't use extensions, it is try to recognize the file type from the movie header. So the problem is that: how to you rename the "getdynavideo" pyscript to the Windows Media Player is see the extension of the file, and use the QUERY_STRING with video id. The first todo is to you modify the script name from "getdynavideo" to "getdynavideo.mpeg" (if you use mpeg type video). Next is to modify the page source. The Windows Media Player is working better with "object" tag. See that:
<div tal:define="vurl python:here.REQUEST.BASE0+'getdynavideo.mpeg?vid='+str(videoid)">
<center>
<table border="1" cellpadding="0" cellspacing="0"><tr><td align="center" class="text">
<object id="MediaPlayer" width="320" height="286"
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
standby="Loading Microsoft Windows Media Player components..."
type="application/x-oleobject"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">
<param name="filename" tal:attributes="value vurl">
<param name="autostart" value="true"> <param name="showcontrols" value="true">
<param name="showstatusbar" value="true"> <param name="autorewind" value="true">
<param name="showdisplay" value="false">
<embed width="320" height="286"
type="application/x-mplayer2"
name="mediaplayer"
autostart="1" showcontrols="0"
showstatusbar="1" autorewind="1"
showdisplay="0" tal:attributes="src vurl">
</embed>
</object>
</td></tr></table>
<br>
<a border="0" tal:attributes="href python:vurl">Download the movie here...</a><br>
</center>
</div>
When you try it, you'll see that is working good in Internet Explorer ! A very interesting thing: When I tried this example in Opera, or Mozilla, and I used Zope in local machine, it is worked good. But when I copied this "Data.fs" to Debian Linux server, and I tried to load the page, only the IE was working. The Mozilla, and the Opera tried to load the "embed" tag, and the browser was frozen by the Media Player... When it is happening, you simply change one of the embed's tag from: type="application/x-mplayer2" To: type="video/mpeg"And you need to use the QuickTime Player in your machine to view the video. You can find the export of the tests project here... That's all. |