Use deezer audio preview in OGG format with on the fly conversion for Audio HTML5 Tag
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
php
README.md

README.md

Deezer ogg preview conversion

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

Deezer API

Read more about Deezer API

Requirements

  • ffmpeg
  • php

ffmpeg install (Debian)

sudo apt-get update
sudo apt-get install ffmpeg

Conversion Test

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

How to use ?

  • 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.

Example code

 <?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
 
 ?>