Home Web Front-end JS Tutorial Basic usage tutorial of jPlayer, a web audio and video player based on jQuery_jquery

Basic usage tutorial of jPlayer, a web audio and video player based on jQuery_jquery

May 16, 2016 pm 03:11 PM
javascript jquery player video Audio

jPlayer Introduction:

I want to play background music on a web page, but I don’t want to use html tags, because that way the music can only be played after all the music is downloaded, and it is prone to cross-browser compatibility issues, so I chose a player based on jQuery jPlayer does it.

Set the size of jPlayer
Use the constructor to configure jPlayer({size:Object}) to set the height and width of jPlayer.

Use the constructor to configure jPlayer({sizeFull:Object}) to set the full screen size.

Note that jPlayer background color can be set through the constructor configuration jPlayer({backgroundColor:"#RRGGBB"}).

Flash Security Rules
Use the following code to relax the restrictions on jPlayer SWF files, and you can call swf files of any domain name.

flash.system.Security.allowDomain("*");
flash.system.Security.allowInsecureDomain("*");
Copy after login

Deployment

Usually, you need to upload swf files and js files to the js directory under your domain name. Change the swf path using the constructor configuration jPlayer({"swfPath":path}).

Strictly speaking, the plug-in files may be remotely linked to jplayer.org, but we ask you not to link to jplayer.com because we currently do not have sufficient resources to build a CDN. In addition, the Flash playback software on the remote server requires that all multimedia file URLs set by jPlayer("setMedia", media) use absolute paths.


To develop locally, you need to install a server on your computer, such as apache, to enable localhost.

Use Javascript API to control media files on your website jPlayer supported media formats: HTML5: mp3, m4a (AAC), m4v (H.264), ogv*, oga*, wav*, webm* Flash: mp3, m4a (AAC), m4v (H.264)

jPlayer requires two files to be uploaded to your server:

(1)Jplayer.swf

(2)jquery.jplayer.min.js

jPlayer is constructed on jQuery selector. Use the form $(ID).jPlayer(Object: options) to execute the action. In some cases, jPlayer can also be constructed on the body, which means when you don't need to play videos.

Note: swfPath, which defines the path of the jPlayer SWF file. Remember to upload the SWF file to your server! You can also use statements like jPlayer({solution:"flash, html") to specify which method should be used first to play media.

Change settings after initialization
After initialization, use a form similar to jPlayer("option",{key:value}) to change the settings.
Implement a webpage that automatically plays music

$(document).ready(function(){
 $("#jquery_jplayer_1").jPlayer({
 ready: function (event) {
  $(this).jPlayer("setMedia", {
  m4a:"http://www.jplayer.org/audio/m4a/TSP-01-Cro_magnon_man.m4a",
  oga:"http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg"
  });
 },
 swfPath: "js",
 supplied: "m4a, oga",
 }).jPlayer("play");
});
Copy after login

Explain the above code:

The first line "$(document).ready(function(){" is very friendly to everyone, document loading event.

The second line "$("#jquery_jplayer_1").jPlayer({" selects a DIV, which is used to carry HTML5 elements or Flash. You can just write an empty DIV in the document.

The third line "ready: function (event) {", ready is a key, function is a value, something very familiar.

The fourth line "$(this).jPlayer("setMedia", {"this refers to "$("#jquery_jplayer_1")", which means: "$("#jquery_jplayer_1").jPlayer("setMedia ", {" is very familiar. setMedia is an option, according to the second step.

The ninth line "swfPath: "js"," this defines the relative path where the swf player is located. If you do not plan to be compatible with web pages that do not support HTML5, you don’t need to write it :)

Format supported by line 10 "supplied: "m4a, oga",".

The eleventh line "jPlayer("play");" means: $("#jquery_jplayer_1").jPlayer("play");, playing media to achieve automatic playback.

Commonly used methods in jPlayer:

//播放
$("#jpId").jPlayer("play");
//暂停
$("#jpId").jPlayer("pause");
//停止
$("#jpId").jPlayer("stop");
//设置进度相关
//1.按歌曲时长百分比
$("#jpId").jPlayer("playHead", 0);// 从 0% 处开始播放
$("#jpId").jPlayer("playHead", 10);// 从 10% 处开始播放
$("#jpId").jPlayer("playHead", 100);// 从 100% 处开始播放
//2.按播放毫秒数
$("#jpId").jPlayer("playHeadTime", 0);// 从 0毫秒 处开始播放
$("#jpId").jPlayer("playHeadTime", 10000); // 从 10000毫秒(10秒) 处开始播放
//设定音量
$("#jpId").jPlayer("volume", 0.25); //设为最大音量的 25%
//绑定事件
//播放结束事件
$("#jpId").jPlayer("onSoundComplete", function() {
  //alert('播放结束了');
  this.element.jPlayer("play"); // 循环播放
});
//播放进行事件
$("#jpId").jPlayer("onProgressChange", function(lp,ppr,ppa,pt,tt) {
  var s = '缓冲百分比:'+lp +'% ,';
  s += '已播放占已缓冲的百分比:'+ppr +'% ,';
  s += '已播放占总时长的百分比:'+ppa +'%';
  s += '已播放时间:'+pt+ '毫秒 ,';
  s += '总时间:'+tt+ '毫秒';
  $("#play_info").text(s);
});
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is it infringing to post other people's videos on Douyin? How does it edit videos without infringement? Is it infringing to post other people's videos on Douyin? How does it edit videos without infringement? Mar 21, 2024 pm 05:57 PM

With the rise of short video platforms, Douyin has become an indispensable part of everyone's daily life. On TikTok, we can see interesting videos from all over the world. Some people like to post other people’s videos, which raises a question: Is Douyin infringing upon posting other people’s videos? This article will discuss this issue and tell you how to edit videos without infringement and how to avoid infringement issues. 1. Is it infringing upon Douyin’s posting of other people’s videos? According to the provisions of my country's Copyright Law, unauthorized use of the copyright owner's works without the permission of the copyright owner is an infringement. Therefore, posting other people’s videos on Douyin without the permission of the original author or copyright owner is an infringement. 2. How to edit a video without infringement? 1. Use of public domain or licensed content: Public

VLC Chromecast not working on Windows PC VLC Chromecast not working on Windows PC Mar 26, 2024 am 10:41 AM

Is the VLC Chromecast feature not working on your Windows PC? This issue may be caused by compatibility issues between your Chromecast device and VLC’s casting feature. In this article, we will tell you what you can do in this situation and what to do if VLC renderer cannot find your Chromecast. How to use ChromecastVLC on Windows? To use VLC to cast videos from Windows to Chromecast, follow these steps: Open the media player app and go to the play menu. Navigate to the Renderer option and you will be able to see the Chromecast device detected

How to make money from posting videos on Douyin? How can a newbie make money on Douyin? How to make money from posting videos on Douyin? How can a newbie make money on Douyin? Mar 21, 2024 pm 08:17 PM

Douyin, the national short video platform, not only allows us to enjoy a variety of interesting and novel short videos in our free time, but also gives us a stage to show ourselves and realize our values. So, how to make money by posting videos on Douyin? This article will answer this question in detail and help you make more money on TikTok. 1. How to make money from posting videos on Douyin? After posting a video and gaining a certain amount of views on Douyin, you will have the opportunity to participate in the advertising sharing plan. This income method is one of the most familiar to Douyin users and is also the main source of income for many creators. Douyin decides whether to provide advertising sharing opportunities based on various factors such as account weight, video content, and audience feedback. The TikTok platform allows viewers to support their favorite creators by sending gifts,

2 Ways to Remove Slow Motion from Videos on iPhone 2 Ways to Remove Slow Motion from Videos on iPhone Mar 04, 2024 am 10:46 AM

On iOS devices, the Camera app allows you to shoot slow-motion video, or even 240 frames per second if you have the latest iPhone. This capability allows you to capture high-speed action in rich detail. But sometimes, you may want to play slow-motion videos at normal speed so you can better appreciate the details and action in the video. In this article, we will explain all the methods to remove slow motion from existing videos on iPhone. How to Remove Slow Motion from Videos on iPhone [2 Methods] You can use Photos App or iMovie App to remove slow motion from videos on your device. Method 1: Open on iPhone using Photos app

How to publish Xiaohongshu video works? What should I pay attention to when posting videos? How to publish Xiaohongshu video works? What should I pay attention to when posting videos? Mar 23, 2024 pm 08:50 PM

With the rise of short video platforms, Xiaohongshu has become a platform for many people to share their lives, express themselves, and gain traffic. On this platform, publishing video works is a very popular way of interaction. So, how to publish Xiaohongshu video works? 1. How to publish Xiaohongshu video works? First, make sure you have a video content ready to share. You can use your mobile phone or other camera equipment to shoot, but you need to pay attention to the image quality and sound clarity. 2. Edit the video: In order to make the work more attractive, you can edit the video. You can use professional video editing software, such as Douyin, Kuaishou, etc., to add filters, music, subtitles and other elements. 3. Choose a cover: The cover is the key to attracting users to click. Choose a clear and interesting picture as the cover to attract users to click on it.

How to post videos on Weibo without compressing the image quality_How to post videos on Weibo without compressing the image quality How to post videos on Weibo without compressing the image quality_How to post videos on Weibo without compressing the image quality Mar 30, 2024 pm 12:26 PM

1. First open Weibo on your mobile phone and click [Me] in the lower right corner (as shown in the picture). 2. Then click [Gear] in the upper right corner to open settings (as shown in the picture). 3. Then find and open [General Settings] (as shown in the picture). 4. Then enter the [Video Follow] option (as shown in the picture). 5. Then open the [Video Upload Resolution] setting (as shown in the picture). 6. Finally, select [Original Image Quality] to avoid compression (as shown in the picture).

Two solutions for sharing edge browser web videos with no sound Two solutions for sharing edge browser web videos with no sound Mar 14, 2024 pm 02:22 PM

Many users like to watch videos on the browser. If there is no sound when watching web videos on the edge browser, how to solve the problem? This problem is not difficult. Next, let me tell you how to fix the problem of no sound in edge browser web videos. There is no sound in edge browser web videos? Method 1: 1. First, check the top tab of the edge browser. 2. There is a "Sound Button" on the left side of the tab, make sure it is not muted. Method 2: 1. If it is confirmed that the sound is not muted, it may be a sound setting problem. 2. You can right-click the sound device in the lower right corner and select "Open Volume Synthesizer" 3. Open

Douyin 15 seconds is too short and I want to extend it. How can I extend it? How to make a video longer than 15 seconds? Douyin 15 seconds is too short and I want to extend it. How can I extend it? How to make a video longer than 15 seconds? Mar 22, 2024 pm 08:11 PM

With the popularity of Douyin, more and more people like to share their lives, talents and creativity on this platform. Douyin's 15-second limit makes many users feel that it is not enjoyable enough and hope to extend the video duration. So, how can you extend the video duration on Douyin? 1. Douyin 15 seconds is too short and I want to extend it. How can I extend it? 1. The most convenient way to shoot multiple videos and splice them is to record multiple 15-second videos, and then use the editing function of Douyin to combine them. When recording, make sure to leave some blank space at the beginning and end of each video for later splicing. The length of the spliced ​​video can be several minutes, but this may cause the video screen to switch too frequently, affecting the viewing experience. 2. Use Douyin special effects and stickers Douyin provides a series of special effects

See all articles