public function Playlist::getPlaylist in MediaFront 7
Same name and namespace in other branches
- 6.2 players/osmplayer/player/playlist/Playlist.php \Playlist::getPlaylist()
- 6 players/osmplayer/player/playlist/Playlist.php \Playlist::getPlaylist()
Returns the playlist in XML form.
Return value
- The XML format of the playlist.
File
- players/
osmplayer/ player/ playlist/ Playlist.php, line 159
Class
- Playlist
- Playlist Class
Code
public function getPlaylist() {
// Initialize some variables.
$xml = '';
$dirname = dirname(__FILE__);
$playlist_dir = $dirname . '/' . 'playlists' . '/' . $this->playlist;
$playlist_file = $dirname . '/' . 'cache' . '/' . $this->playlist . '.xml';
// If there is already a cache file, then we will just want to use it.
if ($this->cache && file_exists($playlist_file)) {
// Open the cache file and populate the XML variable with its contents.
$handle = fopen($playlist_file, "r");
if ($handle) {
while (!feof($handle)) {
$xml .= fgets($handle, 4096);
}
fclose($handle);
}
}
else {
if (is_dir($playlist_dir)) {
// Here we will want to search for all the media files and their images for the playlist.
$contents = '';
$files = array();
$this
->get_media_files($playlist_dir, $files);
if ($files) {
$url = $this->base_url;
$numfiles = count($files);
// Iterate through all the files.
for ($i = 0; $i < $numfiles; $i++) {
$file = $files[$i];
$image = '';
// If there is an image association.
if (isset($file['image']) && $file['image']) {
// Set the image variable to be used later.
$image = str_replace($dirname, '', $file['image']);
$image = htmlspecialchars($this->base_url . $image);
}
// If there is a media file.
if (isset($file['media']) && $file['media']) {
// Iterate through all the media files in this directory.
foreach ($file['media'] as $media) {
$media = str_replace($dirname, '', $media);
$media = htmlspecialchars($this->base_url . $media);
// Set the contents of this single track listing with
// its associated image file.
switch ($this->schema) {
case SCHEMA_RSS:
$contents .= $this
->rssGetTrack($media, $image);
break;
case SCHEMA_ASX:
$contents .= $this
->asxGetTrack($media, $image);
break;
case SCHEMA_XSPF:
default:
$contents .= $this
->playlistGetTrack($media, $image);
break;
}
}
}
}
}
// Now, set up the whole XML structure given the right schema.
if ($contents) {
switch ($this->schema) {
case SCHEMA_RSS:
$xml = $this
->getRSSXML($contents);
break;
case SCHEMA_ASX:
$xml = $this
->getASXXML($contents);
break;
case SCHEMA_XSPF:
default:
$xml = $this
->getPlaylistXML($contents);
break;
}
}
// Now, let's create our cache file.
if ($this->cache) {
$handle = fopen($playlist_file, "w");
if ($handle) {
fwrite($handle, $xml);
fclose($handle);
}
}
}
else {
print 'Directory ' . $playlist_dir . ' not found';
}
}
// Return the XML structure.
return $xml;
}