Hi,

Here's an rfc patch which adds basic html5 and flash player support. It's 
modeled after the Video for Everybody page 
http://camendesign.com/code/video_for_everybody. Even though that page 
indicates that fallback to flash should happen automatically if the browser 
doesn't support html5, my firefox fails to do that. To work around this I made 
the selection explicit to the user.

The flashplayer needs to be configured with the full URL of the file to play. I 
failed to find a good way to find that info in the code (nb. I run freewo 
behind a forwarding https->http proxy, so it would have to take some client 
side scripting to get at this info.) I solved this by adding a new config 
parameter:

WEBSERVER_URLROOT = "https://WHATEVER.net";

The code could do with some cleaning up if we want to add it, but right now it 
at least works as intended. Comments welcome. My python skills are close to 
nil, so improvements in that area are welcome too.

An improvement I want to do is to use the right poster image for the movies. I 
guess that means either using the cover info from the fxd, or the thumbnail if 
available. Any pointer to code showing how to do that would be appreciated.

A futher improvement is to use the right width and height info. How do I get at
that info? I guess I can get it from the file (using kaa.metadata, I guess),
but I have a fair amount of fxd's which points at mp4 files on the net and I
suspect there's support funtions in freevo for this already. Can an fxd host
that info? (I could pre-populate the fxd's with that info out of band if need
be).

                Anders

diff -uN /tmp/freevo-1.9.0/src/www/htdocs/fileinfo.rpy ./fileinfo.rpy
--- /tmp/freevo-1.9.0/src/www/htdocs/fileinfo.rpy       2009-04-02 
18:50:13.000000000 +0200
+++ ./fileinfo.rpy      2011-01-06 16:01:59.000000000 +0100
@@ -144,6 +144,8 @@
                u"doc.getElementById('file-info').innerHTML = '%s';\n"\
                u"doc.getElementById('file-play-button').onclick = %s;\n"\
                u"doc.getElementById('file-play-using-vlc').onclick = %s;\n"\
+               u"doc.getElementById('file-play-using-html5').onclick = %s;\n"\
+               u"doc.getElementById('file-play-using-flash').onclick = %s;\n"\
                u"doc.getElementById('program-waiting').style.display = 
'none';\n" \
                u"doc.getElementById('program-info').style.visibility = 
'visible';\n" \
                u"</script>\n" \
@@ -151,7 +153,9 @@
             ) % ( Unicode(title.replace("'", "\\'")),
                   Unicode(info.replace("'", "\\'")),
                   "function() { window.open(\"%s\"); }" % 
(urllib.quote(file_link)),
-                  "function() { window.open(\"vlcwin.rpy?dir=%s\"); }" % 
(urllib.quote(file_link))
+                  "function() { window.open(\"vlcwin.rpy?dir=%s\"); }" % 
(urllib.quote(file_link)),
+                  "function() { window.open(\"html5win.rpy?dir=%s\"); }" % 
(urllib.quote(file_link)),
+                  "function() { window.open(\"flashwin.rpy?dir=%s\"); }" % 
(urllib.quote(file_link))
             )
 
         elif img:
diff -uN /tmp/freevo-1.9.0/src/www/htdocs/flashwin.rpy ./flashwin.rpy
--- /tmp/freevo-1.9.0/src/www/htdocs/flashwin.rpy       1970-01-01 
01:00:00.000000000 +0100
+++ ./flashwin.rpy      2011-01-07 15:37:41.000000000 +0100
@@ -0,0 +1,93 @@
+# -*- coding: iso-8859-1 -*-
+# 
vim:autoindent:tabstop=4:softtabstop=4:shiftwidth=4:expandtab:filetype=python:
+# -----------------------------------------------------------------------
+# Web interface to play files using flash
+# -----------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------
+
+import sys, os, stat, string, urllib
+import time
+
+from www.web_types import HTMLResource, FreevoResource
+from twisted.web.woven import page
+import util
+import config
+import mimetypes
+import kaa.metadata as metadata
+from twisted.web import static
+
+class FlashWinResource(FreevoResource):
+
+    def __init__(self):
+        #print 'FlashWinResource.__init__(self)'
+        self.allowed_dirs = []
+        self.allowed_dirs.extend(config.VIDEO_ITEMS)
+        self.allowed_dirs.extend(config.AUDIO_ITEMS)
+        self.allowed_dirs.extend( [ ('Recorded TV', config.TV_RECORD_DIR) ])
+        self.allowed_dirs.extend(config.IMAGE_ITEMS)
+
+    def _render(self, request):
+        #print '_render(self, %s)' % (request)
+        fv = HTMLResource()
+        form = request.args
+        file = fv.formValue(form, 'dir')
+
+        if file:
+            file_link = self.convert_dir(file)
+            #print 'file_link=%s' % (file_link)
+            (mimetype, encoding) = mimetypes.guess_type(file_link)
+
+            fv.res += (
+               u"<body>\n" \
+               u"<object type='application/x-shockwave-flash' 
data='http://player.longtailvideo.com/player.swf' width='640' height='480'>\n" \
+               u"<param name='movie' 
value='http://player.longtailvideo.com/player.swf' />\n" \
+               u"<param name='allowFullScreen' value='true' />\n" \
+              u"<param name='wmode' value='transparent' />\n" \
+              u"<param name='flashVars' 
value='controlbar=over&amp;image=%s/M_poster.jpg&amp;file=%s/%s' />\n" \
+              ) % (config.WEBSERVER_URLROOT,config.WEBSERVER_URLROOT, 
urllib.quote(file_link))
+            fv.res += (
+                u"<img alt='Big Buck Bunny' 
src='http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg'
 width='640' height='480' title='No video playback capabilities, please 
download the video below' />\n" \
+                u"</object>\n" \
+                u"</body></html>\n" \
+            )
+
+        return String(fv.res)
+
+    def convert_dir(self, dir_str):
+        #print 'convert_dir(self, dir_str=%r)' % (dir_str)
+        for i in range(len(self.allowed_dirs)):
+            val = self.allowed_dirs[i][1]
+            if dir_str.startswith(val):
+                child_res = val.replace("/", "_")
+                location = dir_str[len(val):]
+                if not location[0] == "/":
+                    child_res += "/"
+                return child_res + location
+        return dir_str
+
+
+resource = FlashWinResource()
diff -uN /tmp/freevo-1.9.0/src/www/htdocs/html5win.rpy ./html5win.rpy
--- /tmp/freevo-1.9.0/src/www/htdocs/html5win.rpy       1970-01-01 
01:00:00.000000000 +0100
+++ ./html5win.rpy      2011-01-07 15:38:25.000000000 +0100
@@ -0,0 +1,89 @@
+# -*- coding: iso-8859-1 -*-
+# 
vim:autoindent:tabstop=4:softtabstop=4:shiftwidth=4:expandtab:filetype=python:
+# -----------------------------------------------------------------------
+# Web interface to html5
+# -----------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------
+
+import sys, os, stat, string, urllib
+import time
+
+from www.web_types import HTMLResource, FreevoResource
+from twisted.web.woven import page
+import util
+import config
+import mimetypes
+import kaa.metadata as metadata
+from twisted.web import static
+
+class Html5WinResource(FreevoResource):
+
+    def __init__(self):
+        #print 'Html5WinResource.__init__(self)'
+        self.allowed_dirs = []
+        self.allowed_dirs.extend(config.VIDEO_ITEMS)
+        self.allowed_dirs.extend(config.AUDIO_ITEMS)
+        self.allowed_dirs.extend( [ ('Recorded TV', config.TV_RECORD_DIR) ])
+        self.allowed_dirs.extend(config.IMAGE_ITEMS)
+
+    def _render(self, request):
+        #print '_render(self, %s)' % (request)
+        fv = HTMLResource()
+        form = request.args
+        file = fv.formValue(form, 'dir')
+
+        if file:
+            file_link = self.convert_dir(file)
+            #print 'file_link=%s' % (file_link)
+            (mimetype, encoding) = mimetypes.guess_type(file_link)
+
+            fv.res += (
+               u"<body>\n" \
+              u"<video controls='controls' 
poster='http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg'
 width='640' height='480'>\n" \
+               u"<source src='/%s' type='%s' />\n" ) % 
(urllib.quote(file_link), mimetype)
+
+            fv.res += (
+                u"</video>\n" \
+                u"</body></html>\n" \
+            )
+
+        return String(fv.res)
+
+    def convert_dir(self, dir_str):
+        #print 'convert_dir(self, dir_str=%r)' % (dir_str)
+        for i in range(len(self.allowed_dirs)):
+            val = self.allowed_dirs[i][1]
+            if dir_str.startswith(val):
+                child_res = val.replace("/", "_")
+                location = dir_str[len(val):]
+                if not location[0] == "/":
+                    child_res += "/"
+                return child_res + location
+        return dir_str
+
+
+resource = Html5WinResource()
diff -uN /tmp/freevo-1.9.0/src/www/htdocs/library.rpy ./library.rpy
--- /tmp/freevo-1.9.0/src/www/htdocs/library.rpy        2009-05-16 
20:10:55.000000000 +0200
+++ ./library.rpy       2011-01-06 16:03:47.000000000 +0100
@@ -602,6 +602,14 @@
             u"                        "+_('Play file using VLC')+u"\n"\
             u"                        "+''+u"\n"\
             u"                        </td>\n"\
+           u"                        <td id=\"file-play-using-html5\">\n"\
+           u"                        "+_('Play file using html5')+u"\n"\
+           u"                        "+''+u"\n"\
+           u"                        </td>\n"\
+            u"                        <td id=\"file-play-using-flash\">\n"\
+            u"                        "+_('Play file using flash')+u"\n"\
+            u"                        "+''+u"\n"\
+            u"                        </td>\n"\
             u"                        <td id=\"program-favorites-button\">\n"\
             #u"                        "+_('Play file on Freevo')+u"\n"\
             u"                        "+''+u"\n"\

 


------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl 
_______________________________________________
Freevo-devel mailing list
Freevo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to