A small script to play audio preview from deezer with html5 audio tag.
Browser :
- Firefox
- Chrome
- Safari (*)
- Internet Explorer (*)
- Opera
(*) Works without ogg format conversion
- ffmpeg
- php
sudo apt-get update
sudo apt-get install ffmpeg
Try to execute this command, if you found a file named test.ogg, then you're brainy ! it works :)
ffmpeg -i http://cdn-preview-a.deezer.com/stream/a4e149e52e2ffdc4f057661b40ba7ee3-1.mp3 -f ogg -strict experimental -acodec vorbis -ab 192k test.ogg
-
Get a deezer track id from Deezer API - you can also use this wrapper for a quick start Deezer-API-PHP-Wrapper
-
Call the function getSample($track_id) or use dzpreview::getPreview($track_id) (The function calls Deezer API to get the audio preview url and directly convert it into ogg format. The ogg file will be stored in a stream folder)
-
getSample or dzpreview::getPreview($track_id) return the path of the ogg file.
<?php
require 'class.dzpreview.php';
$track_id = '12214510';
$baseurl = 'http://myserver.com/';
$path = dzpreview::getPreview($track_id);
echo $baseurl.$path;
//return : http://myserver.com/stream/a/1/a1e6de2ec7f4e0dd35f2523334915ba5-1.ogg
?>