你好!我对潜水艇的专家有一个疑问,我希望有人能指出我正确的方向。我有一个自定义播放器,可以播放服务器中的音乐,并希望通过音频广告获利。我和我的团队一直在努力,但是当我点击播放时,我们似乎无法播放广告。
此link当前面临的问题是生成 XML 文件(URL用于接收来自第三方广告服务器的VAST广告响应),我需要包含来自将 XML响应放入我的播放按钮功能(我不知道该怎么做)以播放广告。
仅供参考,系统基于 PHP 构建,播放器采用jquery构建。与现场广播系统不同,我们的播放器是经过定制的,可以播放数据库中的广告和歌曲,现在我们认为,如果我们的播放器有可用的任意插件,则可以解决我们的问题。 / p>
使用ec2容器实例通过AWS服务器播放歌曲。
该网络应用程序已经live
以下是用于播放器的库和代码。
<script src="libs/mediaelement/build/mediaelement-and-player.min.js" type="text/javascript"></script>
<script src="libs/mediaelement/build/mep.js" type="text/javascript"></script>
以下脚本用于将播放列表和其他资源(例如播放/暂停/喜欢等)创建到网站中
<script type="text/javascript">
//(function ($) {
//"use strict";
$(document).ready(function(){
if($('.playlist').length == 0) return;
var adPlayed = false;
var prerollWidget;
var playlist = $( '.playlist' ).mepPlaylist({
audioHeight: '40',
audioWidth: '100%',
videoHeight: '40',
videoWidth: '100%',
audioVolume: 'vertical',
mepPlaylistLoop: true,
enableKeyboard: false,
alwaysShowControls: true,
mepSkin: 'mejs-audio',
mepResponsiveProgress: true,
vastAdTagUrl:'http://cmod677.live.streamtheworld.com/ondemand/ars?version=1.6.4&banners=300x250&type=midroll&stid=256793&gdpr=1',
vastAdsType:'vast',
mepSelectors: {
playlist: '.playlist',
track: '.track',
tracklist: '.tracks'
},
features: [
'meplike',
'mepshare',
'mepartwork',
'mepcurrentdetails',
'mepplaylist',
'mephistory',
'mepprevioustrack',
'playpause',
'mepnexttrack',
'current',
'duration',
'volume',
'mepicons',
'meprepeat',
'mepshuffle',
'mepsource',
'mepbuffering',
'meptracklist',
'playlistfeature',
'postroll',
/'mepplaylisttoggle',/
'youtube'
],
mepPlaylistTracks: [
{
"id": "8",
"link": "track.detail.php?id=8",
"title": "Jimmy",
"thumb": { "src": "cover/song_cover/logo_sln.png" },
"src": "http://soundslikenoise.s3.amazonaws.com/Jimmy.mp3",
"meta": {
"author": "by Amit Singh",
"authorlink": "artist.php",
}
},
{
"id": "9",
"link": "track.detail.php?id=9",
"title": "Working Man",
"thumb": { "src": "cover/song_cover/logo_sln.png" },
"src": "http://soundslikenoise.s3.amazonaws.com/Working-Man.mp3",
"meta": {
"author": "by Amit Singh",
"authorlink": "artist.php",
}
},
{
"id": "5",
"link": "track.detail.php?id=5",
"title": "Allah Duhai Hai",
"thumb": { "src": "cover/song_cover/race-3-s_1533041255.jpg" },
"src": "http://soundslikenoise.s3.amazonaws.com/AllahDuhaiHai.mp3",
"meta": {
"author": "by Amit Singh",
"authorlink": "artist.php",
}
},
{
"id": "12",
"link": "track.detail.php?id=12",
"title": "Get Low",
"thumb": { "src": "cover/song_cover/getlow_1537337849.jpg" },
"src": "https://soundslikenoise.s3.amazonaws.com/GetLow.mp3",
"meta": {
"author": "by Amit Singh",
"authorlink": "artist.php",
}
},
{
"id": "6",
"link": "track.detail.php?id=6",
"title": "Molly",
"thumb": { "src": "cover/song_cover/logo_sln.png" },
"src": "http://soundslikenoise.s3.amazonaws.com/Molly.mp3",
"meta": {
"author": "by Amit Singh",
"authorlink": "artist.php",
}
},
{
"id": "1",
"link": "track.detail.php?id=1",
"title": "Sharabi",
"thumb": { "src": "cover/song_cover/logo_sln.png" },
"src": "http://soundslikenoise.s3.amazonaws.com/Sharabi.mp3",
"meta": {
"author": "by Amit Singh",
"authorlink": "artist.php",
}
},
{
"id": "7",
"link": "track.detail.php?id=7",
"title": "Tip Toe",
"thumb": { "src": "cover/song_cover/logo_sln.png" },
"src": "http://soundslikenoise.s3.amazonaws.com/Tip-Toe.mp3",
"meta": {
"author": "by Amit Singh",
"authorlink": "artist.php",
}
},
{
"id": "11",
"link": "track.detail.php?id=11",
"title": "Aao Kabhi Haveli Pe",
"thumb": { "src": "cover/song_cover/62470299_1537292143.jpg" },
"src": "https://soundslikenoise.s3.amazonaws.com/Aao_Kabhi_Haveli_Pe.mp3",
"meta": {
"author": "by Rajeev Rahi",
"authorlink": "artist.php",
}
},
]
});
var player = playlist.find('audio, video')[0].player;
// get player, then you can use the player.mepAdd(), player.mepRemove(), player.mepSelect()
player.$node.on('play.mep', function(e) {
var track=this.src;
$.ajax({
type : 'POST',
url : 'lib/like.php?action=play_count',
data : 'track='+track+'&&user_id=0',
});
loadDoc();
updateDisplay();
// player.play();
});
var id = $("#myBtn").attr("track-id");
player.$node.on('like.mep', function(e, trackid){
//alert(trackid);
$.ajax({
type : 'POST',
url : 'lib/like.php?action=like_songs',
data : 'track_id='+trackid+'&&user_id=0',
success : function(data) {
//console.log(data);
//alert(data);
if(data=='<span style="color:green;padding-right:10px;font-size:20px"><i class="fa fa-check"></i></span>This song has been added as your favorite')
{
$('[track-id='+trackid+']').toggleClass('is-like');
// document.getElementById('favorite').value=data;
$("#myModal").modal();
$('#favorite').html(data);
}
else
{
$('[track-id='+trackid+']').toggleClass('');
// document.getElementById('favorite').value=data;
$("#myModal").modal();
$('#favorite').html(data);
}
}
});
//alert(trackid);
/*if(trackid)
{
window.location.href="lib/like.php?action=like_songs&&track_id="+trackid+"&&user_id=";
}*/
//$('[track-id='+trackid+']').toggleClass('is-like');
});
player.$node.on('share.mep', function(e, trackid){
//alert(trackid);
var songID=$('#songs').text(trackid);
});
// event on play
// event on pause
player.$node.on('pause', function(e){
// alert(trackid);
updateDisplay();
});
// update when pjax end
$(document).on('pjaxEnd', function() {
updateDisplay();
});
// simulate the play btn
$(document).on('click.btn', '.btn-playpause', function(e, trackid){
// alert(trackid);
e.stopPropagation();
var self = $(this);
//alert(trackid);
if( self.hasClass('is-playing') ){
self.removeClass('is-playing');
player.pause();
}else{
var item = getItem(self);
item && player.mepAdd(item, true);
}
});
function updateDisplay(){
$('[data-id]').removeClass('active').find('.btn-playpause').removeClass('is-playing').parent().removeClass('active');
var track = player.mepGetCurrentTrack();
if(!track || !track.id) return;
var item = $('[data-id="'+track.id+'"]');
//alert(item);
if( player.media.paused ){
item.removeClass('active').find('.btn-playpause').removeClass('is-playing').parent().removeClass('active');
}else{
item.addClass('active').find('.btn-playpause').addClass('is-playing').parent().addClass('active');
}
}
// get item data, you can use ajax to get data from server
function getItem(self){
var item = self.closest('.item');
// track detail
if(!item.attr('data-src')){
self.toggleClass('is-playing');
$('#tracks').find('.btn-playpause').first().trigger('click');
return false;
}
var obj = {
meta: {
author: item.find('.item-author').find('a').text()
,authorlink : item.find('.item-author').find('a').attr('href')
}
,src: self.closest('[data-src]').attr("data-src")
,thumb: {
src: item.find('.item-media-content').css("background-image").replace(/^url\(["']?/, '').replace(/["']?\)$/, '')
}
,title: item.find('.item-title').find('a').text()
,link: item.find('.item-title').find('a').attr('href')
,id: self.attr("data-id") ? self.attr("data-id") : self.closest('[data-id]').attr("data-id")
};
return obj;
}
/*function loadDoc(src) {
//debugger;
// Player settings
var src = {
hls: src
};
// Player settings
var settings = {
licenseKey: 'Y2trY3FlYW9nZyEqXyUwZThrejBjc2F2a2VzMHYyeT0/cm9tNWRhc2lzMzBkYjBBJV8q',
src: src,
width: 1903,
// Enabling ads
ads: true,
adTagUrl: 'http://cmod677.live.streamtheworld.com/ondemand/ars?version=1.6.4&banners=300x250&type=midroll&stid=256793&gdpr=1',
adTagWaterfall: [
'http://cmod677.live.streamtheworld.com/ondemand/ars?version=1.6.4&banners=300x250&type=midroll&stid=256793&gdpr=1'
],
audioOnly: true
};
var elementID = 'mep_0';
var rmp = new RadiantMP(elementID);
rmp.init(settings);
}*/
function loadDoc() {
var xhttp = new XMLHttpRequest();
var xmlDoc='';
xhttp.open("GET", "http://cmod677.live.streamtheworld.com/ondemand/ars?version=1.6.4&banners=300x250&type=midroll&stid=256793&gdpr=1", true);
xhttp.send();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
xmlDoc = this.responseText;
console.log(xmlDoc.getElementsByTagName('MediaFiles'));
}
};
}
});
//})(jQuery);
</script>
预先感谢您:o)