This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/handle_mp3/theme.php

42 lines
1.3 KiB
PHP
Raw Normal View History

<?php
class MP3FileHandlerTheme extends Themelet {
2009-01-04 19:54:16 +00:00
public function display_image(Page $page, Image $image) {
$data_href = get_base_href();
$ilink = $image->get_image_link();
2012-01-31 15:00:06 +00:00
$fname = url_escape($image->filename); //Most of the time this will be the title/artist of the song.
$html = "
<audio controls class='shm-main-image audio_image' id='main_image' alt='main image'>
<source src=\"$ilink\" type=\"audio/mpeg\">
Your browser does not support the audio element.
</audio>
<p>Title: <span id='audio-title'>???</span> | Artist: <span id='audio-artist'>???</span></p>
<script>
$('#main_image').prop('volume', 0.25);
var jsmediatags = window.jsmediatags;
jsmediatags.read(location.origin+base_href+'$ilink', {
onSuccess: function(tag) {
var artist = tag.tags.artist,
title = tag.tags.title;
$('#audio-title').text(title);
$('#audio-artist').text(artist);
$('#audio-download').prop('download', (artist+' - '+title).substr(0, 250)+'.mp3');
},
onError: function(error) {
console.log(error);
}
});
</script>
<p><a href='$ilink' id='audio-download'>Download</a>";
$page->add_html_header("<script src='{$data_href}/ext/handle_mp3/lib/jsmediatags.min.js' type='text/javascript'></script>");
2012-03-19 19:09:52 +00:00
$page->add_block(new Block("Music", $html, "main", 10));
}
}