Jplayer学习

本文详细介绍了如何使用JPlayer插件创建一个功能丰富的MP3播放器,包括中文显示、颜色选择、播放模式等特性,并提供了一个自定义外观的例子。通过实例演示了如何将JPlayer集成到网站中,实现个性化音乐播放体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Jplayer介绍:

JPlayer是一个用于控制和播放mp3文件的jQuery插件,官方宣称The jQuery HTML5 Audio /Video Library。它在后台使用Flash来播放mp3文件,前台播放器外观完全可以使用 XHML/CSS自定义,并有充分的api可供调用,网上很多大神基于Jplayer开发了很多播放器。Janus最初是从城落电台看到专辑列表播放模式 好奇开始搜寻,在这里提供的是在官方基础上稍微修改的Jpalyer,主要特点有:完美支持中文现实;Blue/Red双色供选;五种播放模式。

官网:http://www.jplayer.org/

文档:http://www.jplayer.org/latest/developer-guide/

下载:http://www.jplayer.org/download/

例子:http://www.jplayer.org/latest/demos/

jplayer的使用上官网看看文档或者上网找找资料也就OK了。

注意:好像播放mp3要有服务器环境。

 

Jplay播放Mp3一个自定义播放器外观例子,该例子没有经过验证

效果http://dj520.92game.net/

 

<script language="javascript" type="text/javascript">
    var play_mode = "rand";
    var loop_mode = "list";
    $(document.body).ready(function() {
        $.jPlayer.timeFormat.showHour = true;
        $("#player").jPlayer({
            ready: function(event) {
                $("#list").get(0).selectedIndex = 0;
                $("#list").trigger("change")
            },
            play: function(event) {
                $(".song-name").html(event.jPlayer.status.media.title);
                varid = event.jPlayer.status.media.id;
                varsrc = event.jPlayer.status.src;
                if (id != "undefined") {
                    $("#download").attr("target", "_blank");
                    $("#download").attr("href", src)
                } else {
                    $("#download").attr("target", "");
                    $("#download").attr("href", "#");
                    returnfalse
                }
            },
            ended: function(event) {
                $(".song-name").html("播放完毕");
                if (play_mode == "single" && loop_mode == "single") {
                    varindex = $("#list").get(0).selectedIndex;
                    $("#list").get(0).selectedIndex = index;
                    $("#list").trigger("change")
                }
                elseif(play_mode == "rand") {
                    varmax = document.getElementById("list").options.length;
                    vartargetIndex = GetRandomNum(0, max);
                    $("#list").get(0).selectedIndex = targetIndex;
                    $("#list").trigger("change")
                }
                $(".song-name").html("欢迎使用DJ前卫音乐网播放器!")
            },
            timeupdate: function(event) {
                varpercent = (event.jPlayer.status.currentTime / event.jPlayer.status.duration) * 100;
                $(".seek-bar").css("width", percent + "%");
                $("#duration").html($.jPlayer.convertTime(event.jPlayer.status.duration))
            },
            supplied: "m4a",
            swfPath: "js",
            wmode: "window",
            loop: false,
            volume: 1,
            cssSelectorAncestor: "",
            cssSelector: {
                currentTime: "#playtime",
                duration: "#totaltime",
                seekBar: ".download-bar",
                playBar: ".seek-bar",
                play: ".play",
                pause: ".pause",
                mute: ".mute",
                unmute: ".unmute",
                volumeBar: "#volumn",
                volumeBarValue: ".volumn-bar"
            }
        });
        $(".btn-stop").click(function() {
            $("#playing-state").html("播放停止");
            $("#playing-songname").html("欢迎使用DJ前卫音乐网播放器!");
            $("#player").jPlayer("stop");
            return false
        });
        $("#list").change(function() {
            varurl = $("#list").find("option:selected").val();
            varsongname = $("#list").find("option:selected").text();
            varid = $("#list").find("option:selected").attr("downloadid");
            $("#player").jPlayer("setMedia", {
                title: songname,
                m4a: url,
                id: id
            }).jPlayer("play")
        });
        $(".pre,.next").click(function() {
            vartargetIndex = -1;
            varindex = $("#list").get(0).selectedIndex;
            varmode = null;
            varstate = $("#playing-state").html();
            mode = play_mode;
            switch (mode) {
            case "rand":
                {
                    varmax = document.getElementById("list").options.length;
                    if (loop_mode == "single") {
                        targetIndex = index
                    } else {
                        if (this.className == "premode-bg") {
                            if (index == 0) {
                                targetIndex == document.getElementById("list").options.length - 1
                            } else {
                                targetIndex = index - 1
                            }
                        }
                        elseif(this.className == "next mode-bg") {
                            if (index == document.getElementById("list").options.length - 1) {
                                targetIndex = 0
                            } else {
                                targetIndex = index + 1
                            }
                        }
                    }
                    break
                }
            case "single":
                {
                    if (this.className == "premode-bg") {
                        if (index == 0) {
                            targetIndex = document.getElementById("list").options.length - 1
                        } else {
                            targetIndex = index - 1
                        }
                    }
                    elseif(this.className == "next mode-bg") {
                        if (index == document.getElementById("list").options.length - 1) {
                            targetIndex = 0
                        } else {
                            targetIndex = index + 1
                        }
                    }
                    break
                }
            case "order":
                {
                    if (loop_mode == "single") {
                        targetIndex = index
                    } else {
                        if (this.className == "premode-bg") {
                            if (index == 0) {
                                if (loop_mode == "list") {
                                    targetIndex = document.getElementById("list").options.length - 1
                                }
                                elseif(loop_mode == "none") {
                                    $(".btn-stop").trigger("click")
                                }
                            } else {
                                targetIndex = index - 1
                            }
                        }
                        elseif(this.className == "next mode-bg") {
                            if (index == document.getElementById("list").options.length - 1) {
                                if (loop_mode == "list") {
                                    targetIndex = 0
                                }
                                elseif(loop_mode == "none") {
                                    $(".btn-stop").trigger("click")
                                }
                            } else {
                                targetIndex = index + 1
                            }
                        } else {
                            returnfalse
                        }
                    }
                    break
                }
            }
            if (targetIndex != -1) {
                $("#list").get(0).selectedIndex = targetIndex;
                $("#list").trigger("change")
            }
            returnfalse
        });
        $(".controlsspan a").click(function() {
            $(".controlsspan a.order-mode").removeClass("order-mode-select");
            $(".controlsspan a.random-mode").removeClass("random-mode-select");
            $(".controlsspan a.single-mode").removeClass("single-mode-select");
            varcurrent_classname = $(this).attr("class").split(" ")[0];
            $(this).addClass(current_classname + "-select");
            switch (current_classname) {
            case "order-mode":
                {
                    play_mode = "order";
                    loop_mode = "list";
                    break
                }
            case "single-mode":
                {
                    play_mode = "single";
                    loop_mode = "single";
                    break
                }
            case "random-mode":
                {
                    play_mode = "rand";
                    loop_mode = "list";
                    break
                }
            }
            returnfalse
        })
    });
</script>

 

该代码没有经过验证,只是提供一种自定义播放器外观的方法

效果http://dj520.92game.net/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值