简体   繁体   English

如何使用HTML5,Jplayer和mysql从播放列表中跟踪歌曲播放?

[英]How do I track song plays from playlist using HTML5, Jplayer and mysql?

I am building a custom based player which will have access to 3 play lists. 我正在构建一个基于自定义的播放器,该播放器可以访问3个播放列表。 The client selects the playlist they want to hear. 客户选择他们想听的播放列表。 At the end of the day I need someway of counting how many times each song on that playlist was listened to. 在一天结束时,我需要某种方式来计算该播放列表中每首歌曲被收听了多少次。 Can this be done in HTML5 or do I need to do this in php and MySql. 可以在HTML5中完成此操作,还是需要在php和MySql中执行此操作。 This has to work for both iOS, Ipad,as well as windows and android. 这必须适用于iOS,Ipad以及Windows和android。

I've done something like this before, and the solution I came up with was having the MP3 files accessed via a PHP file, which registers the request in a database and then fetches the file and serves it (adding headers so the browser recognizes it as an MP3). 我之前已经做过类似的事情,我想出的解决方案是通过PHP文件访问MP3文件,该文件将请求注册到数据库中,然后获取文件并提供服务(添加标头,以便浏览器可以识别它作为MP3)。 Something like: 就像是:

//track the file after you've confirmed it's a valid request (filename passed in URL as //在确认文件有效后跟踪文件(URL中传递的文件名为

?mp3=[mp3 filename]
$logged = track_this($_GET['mp3']); //some tracking function

//now spit it out...

$file_name = "song_name.mp3";
$file = '/path/to/files/'.$_GET['mp3'].'.mp3';

$mm_type="application/octet-stream";

header("Cache-Control: public, must-revalidate");
header("Pragma: hack"); 
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($file)) );
header('Content-Disposition: attachment; filename="'.$file_name.'"');
header("Content-Transfer-Encoding: binary\n");

print file_get_contents($file);

it works pretty well, though you can't track whether they stopped the track part way through (so it's pretty simple metrics) 效果不错,尽管您无法跟踪他们是否在整个过程中都停止了跟踪(因此这是非常简单的指标)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM