Difference between revisions of "MediaRSS"
From A-SMIL.org
(Added Related links) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | SMIL players | + | 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 XPath library. | + | One way to convert a media RSS feed into a SMIL feed is to use the PHP 5 XPath library. |
+ | |||
+ | <STRONG>This is only intended for illustration.</STRONG> 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. | ||
<source lang="php"> | <source lang="php"> | ||
<?php | <?php | ||
+ | $result = ''; | ||
$doc = new DOMDocument(); | $doc = new DOMDocument(); | ||
Line 13: | Line 16: | ||
$xpath->registerNamespace("media", | $xpath->registerNamespace("media", | ||
"http://search.yahoo.com/mrss/"); | "http://search.yahoo.com/mrss/"); | ||
− | $nodes = $xpath->query('/ | + | $nodes = $xpath->query('//media:content', $doc); |
− | $ttlnode= $xpath->query('/rss/channel/ttl',$doc); | + | $ttlnode= $xpath->query('/rss/channel/ttl', $doc); |
− | + | $result .= '<smil><head>' | |
− | + | ||
− | + | ||
.'<layout><root-layout width="1280" height="720"/>' | .'<layout><root-layout width="1280" height="720"/>' | ||
.'</layout><meta http-equiv="Refresh" content="' | .'</layout><meta http-equiv="Refresh" content="' | ||
Line 27: | Line 28: | ||
foreach( $nodes as $node ) | foreach( $nodes as $node ) | ||
{ | { | ||
− | + | $result .= "\t<img src=\"" | |
. $node->attributes->getNamedItem('url') | . $node->attributes->getNamedItem('url') | ||
->textContent | ->textContent | ||
Line 36: | Line 37: | ||
} | } | ||
− | + | $result .= '</seq></body></smil>' ; | |
} | } | ||
+ | header( 'Content-Type: application/smil' ); | ||
+ | header( 'Content-Length: ' . strlen( $result ) ); | ||
+ | header( 'Cache-Control: no-cache' ); | ||
+ | |||
+ | echo $result; | ||
?> | ?> | ||
</source> | </source> | ||
Line 44: | Line 50: | ||
== Related == | == Related == | ||
+ | * [[Checking for Updates]] without restarting playback | ||
* [[Pull mode]] for SMIL | * [[Pull mode]] for SMIL | ||
* [[transport|SMIL transport]] | * [[transport|SMIL transport]] | ||
* [[SMIL_Connectivity|SMIL connectivity]] | * [[SMIL_Connectivity|SMIL connectivity]] |
Latest revision as of 04:11, 30 November 2009
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.
This is only intended for illustration. 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.
<?php $result = ''; $doc = new DOMDocument(); if( $doc->load('http://rss.server.com/mediarssfeed') ) // place your feed here { $xpath = new DOMXPath($doc); $xpath->registerNamespace("media", "http://search.yahoo.com/mrss/"); $nodes = $xpath->query('//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 .'"/></head>' ."<body><seq repeatCount=\"indefinite\">\r\n" ; foreach( $nodes as $node ) { $result .= "\t<img src=\"" . $node->attributes->getNamedItem('url') ->textContent . "\" dur=\"" . $node->attributes->getNamedItem('duration') ->textContent . "\" />\r\n" ; } $result .= '</seq></body></smil>' ; } header( 'Content-Type: application/smil' ); header( 'Content-Length: ' . strlen( $result ) ); header( 'Cache-Control: no-cache' ); echo $result; ?>
Related
- Checking for Updates without restarting playback
- Pull mode for SMIL
- SMIL transport
- SMIL connectivity