Revision as of 19:33, 18 November 2009 by SMIL T.A. (talk | contribs) (Add note for scalable method)
Jump to: navigation, search

A-SMIL players support configuring a "Content Source" URL which is loaded at boot time (see "Pull mode" for general usage). To make a SMIL player play from a Media RSS feed, simply set up a dynamic script (.aspx, .php, etc.) that takes a Media RSS feed and outputs SMIL, then point your SMIL player to the dynamic script.

One way to convert a media RSS feed into a SMIL feed is to use the PHP 5 XPath library.

Note: while this is a convenient way to generate SMIL, this is bad for if you intend to scale. See Best Practice: Checking for Updates for a scalable method to convert live feeds into SMIL.

        $result = '';

        $doc = new DOMDocument();

        if( $doc->load('') ) // place your feed here
                $xpath = new DOMXPath($doc);
                $nodes = $xpath->query('/rss/channel/item/media:content',$doc);
                $ttlnode= $xpath->query('/rss/channel/ttl',$doc);

                $result .= '<smil><head>'
                        .'<layout><root-layout width="1280" height="720"/>'
                        .'</layout><meta http-equiv="Refresh" content="'
                        .$ttlnode->item(0)->textContent * 60
                        ."<body><seq repeatCount=\"indefinite\">\r\n" ;

                foreach( $nodes as $node )
                        $result .= "\t<img src=\""
                                . $node->attributes->getNamedItem('url')
                                . "\" dur=\""
                                . $node->attributes->getNamedItem('duration')
                                . "\" />\r\n" ;

                $result .= '</seq></body></smil>' ;

        header( 'Content-Type: application/smil' );
        header( 'Content-Length: ' . strlen( $result ) );
        header( 'Cache-Control: no-cache' );

        echo $result;