问题描述
Wordpress的音频播放列表很酷,但是不幸的是,每次播放完歌曲时,它会自动跳到下一首曲目,这很烦人.我所知道的是,它与"wp-playlist.min.js"(可能位于此处)有关:
Wordpress has a cool audio playlist but unfortunately it jumps to next tracks automatically every time it finishes playing the song which is annoying. all I know is it has "probably" something to do with wp-playlist.min.js located here:
wordpress \ wp-includes \ js \ mediaelement
wordpress\wp-includes\js\mediaelement
之所以这样说,是因为我在Google上四处搜寻,并且可以通过更改以下行来阻止它循环播放:
I'm saying it because I googled around and I could stop it from looping by changing this line:
(this.index=0,this.setCurrent())}
对此:
(this.index=0)
但是问题是我如何阻止它独自跳到下一首曲目?
But the question is how would I stop it from jumping to next tracks on its own ?
以下是与wp-playlist.min.js相关的代码:
here's the codes related to wp-playlist.min.js:
!function(a,b,c){"use strict";var d=c.View.extend({initialize:function(d){this.index=0,this.settings={},this.data=d.metadata||a.parseJSON(this.$("script.wp-playlist-script").html()),this.playerNode=this.$(this.data.type),this.tracks=new c.Collection(this.data.tracks),this.current=this.tracks.first(),"audio"===this.data.type&&(this.currentTemplate=wp.template("wp-playlist-current-item"),this.currentNode=this.$(".wp-playlist-current-item")),this.renderCurrent(),this.data.tracklist&&(this.itemTemplate=wp.template("wp-playlist-item"),this.playingClass="wp-playlist-playing",this.renderTracks()),this.playerNode.attr("src",this.current.get("src")),b.bindAll(this,"bindPlayer","bindResetPlayer","setPlayer","ended","clickTrack"),b.isUndefined(window._wpmejsSettings)||(this.settings=b.clone(_wpmejsSettings)),this.settings.success=this.bindPlayer,this.setPlayer()},bindPlayer:function(a){this.mejs=a,this.mejs.addEventListener("ended",this.ended)},bindResetPlayer:function(a){this.bindPlayer(a),this.playCurrentSrc()},setPlayer:function(a){this.player&&(this.player.pause(),this.player.remove(),this.playerNode=this.$(this.data.type)),a&&(this.playerNode.attr("src",this.current.get("src")),this.settings.success=this.bindResetPlayer),this.player=new MediaElementPlayer(this.playerNode.get(0),this.settings)},playCurrentSrc:function(){this.renderCurrent(),this.mejs.setSrc(this.playerNode.attr("src")),this.mejs.load(),this.mejs.play()},renderCurrent:function(){var a,b="wp-includes/images/media/video.png";"video"===this.data.type?(this.data.images&&this.current.get("image")&&-1===this.current.get("image").src.indexOf(b)&&this.playerNode.attr("poster",this.current.get("image").src),a=this.current.get("dimensions").resized,this.playerNode.attr(a)):(this.data.images||this.current.set("image",!1),this.currentNode.html(this.currentTemplate(this.current.toJSON())))},renderTracks:function(){var b=this,c=1,d=a('<div class="wp-playlist-tracks"></div>');this.tracks.each(function(a){b.data.images||a.set("image",!1),a.set("artists",b.data.artists),a.set("index",b.data.tracknumbers?c:!1),d.append(b.itemTemplate(a.toJSON())),c+=1}),this.$el.append(d),this.$(".wp-playlist-item").eq(0).addClass(this.playingClass)},events:{"click .wp-playlist-item":"clickTrack","click .wp-playlist-next":"next","click .wp-playlist-prev":"prev"},clickTrack:function(a){a.preventDefault(),this.index=this.$(".wp-playlist-item").index(a.currentTarget),this.setCurrent()},ended:function(){this.index+1<this.tracks.length?this.next():(this.index=0)},next:function(){this.index=this.index+1>=this.tracks.length?0:this.index+1,this.setCurrent()},prev:function(){this.index=this.index-1<0?this.tracks.length-1:this.index-1,this.setCurrent()},loadCurrent:function(){var a=this.playerNode.attr("src")&&this.playerNode.attr("src").split(".").pop(),b=this.current.get("src").split(".").pop();this.mejs&&this.mejs.pause(),a!==b?this.setPlayer(!0):(this.playerNode.attr("src",this.current.get("src")),this.playCurrentSrc())},setCurrent:function(){this.current=this.tracks.at(this.index),this.data.tracklist&&this.$(".wp-playlist-item").removeClass(this.playingClass).eq(this.index).addClass(this.playingClass),this.loadCurrent()}});a(document).ready(function(){a(".wp-playlist").each(function(){return new d({el:this})})}),window.WPPlaylistView=d}(jQuery,_,Backbone);
推荐答案
如果尚未找到答案,可以轻松修改源文件,则可以在指出的文件上编辑"ended"事件.
If you have not found an answer to this, and feel comfortable modifying source files you could edit the 'ended' event on the file you point out.
ended:function(){this.index+1<this.tracks.length?this.next():(this.index=0,this.setCurrent())}
this.next()是更改为下一首歌曲的歌曲.this.index = 0返回播放列表的开头.
The this.next() is the one that changes to the next song. The this.index=0 returns to the start of the playlist.
要停止播放器自己跳到下一首歌曲,请注释this.next指令.
To stop the player to jump to the next song on it's own, comment the this.next instruction.
这篇关于如何停止Wordpress音频播放列表自动播放下一个音轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!