jquery怎么设置audio的loop
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery怎么设置audio的loop相关的知识,希望对你有一定的参考价值。
这个东西最好用原生js效果更好,速度更快,给你个全点的例子
<script>var audio ;
window.onload = function()
initAudio();
var initAudio = function()
//audio = document.createElement("audio")
//audio.src='Never Say Good Bye.ogg'
audio = document.getElementById('audio');
//audio.loop="loop";//这里就可以直接设置loop了
function getCurrentTime(id)
alert(parseInt(audio.currentTime) + ':秒');
function playOrPaused(id,obj)
if(audio.paused)
audio.play();
obj.innerhtml='暂停';
return;
audio.pause();
obj.innerHTML='播放';
function hideOrShowControls(id,obj)
if(audio.controls)
audio.removeAttribute('controls');
obj.innerHTML = '显示控制框'
return;
audio.controls = 'controls';
obj.innerHTML = '隐藏控制框'
return;
function vol(id,type , obj)
if(type == 'up')
var volume = audio.volume + 0.1;
if(volume >=1 )
volume = 1 ;
audio.volume = volume;
else if(type == 'down')
var volume = audio.volume - 0.1;
if(volume <=0 )
volume = 0 ;
audio.volume = volume;
document.getElementById('nowVol').innerHTML = returnFloat1(audio.volume);
function muted(id,obj)
if(audio.muted)
audio.muted = false;
obj.innerHTML = '开启静音';
else
audio.muted = true;
obj.innerHTML = '关闭静音';
//保留一位小数点
function returnFloat1(value)
value = Math.round(parseFloat(value) * 10) / 10;
if (value.toString().indexOf(".") < 0)
value = value.toString() + ".0";
return value;
</script>
<a href="javascript:void(0);" onclick="getCurrentTime('firefox');">获取播放时间</a>
<a href="javascript:void(0);" onclick="playOrPaused('firefox',this);">播放</a>
<a href="javascript:void(0);" onclick="hideOrShowControls('firefox',this);">隐藏控制框</a>
<a href="javascript:void(0);" onclick="muted('firefox',this);">开启静音</a>
<input type="button" value="+" id="upVol" onclick="vol('firefox' , 'up' , this )"/>音量<input type="button" value="-" onclick="vol('firefox' , 'down' ,this )"/>
<audio src="/images/audio/Never Say Good Bye.ogg" id="audio" controls="controls" ></audio>
当前音量:<span id = "nowVol"> - </span> 参考技术A <audio controls="controls" loop="loop">
<source src="song.ogg" type="audio/ogg" />
<source src="song.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
PlayerTest
using UnityEngine;
using System.Collections;
public class PlayTest : MonoBehaviour
{
//电影纹理
public MovieTexture mov;
void Start()
{
audio.clip = mov.audioClip;
audio.Play();
mov.Play();
//设置电影纹理播放模式为循环
mov.loop = true;
}
void OnGUI()
{
if (GUI.Button(new Rect(310, 0, 100, 50), "2倍速播放"))
{
audio.pitch = 2f;
}
if (GUI.Button(new Rect(410, 0, 100, 50), "1倍速播放"))
{
audio.pitch = 1f;
}
GUI.DrawTexture(new Rect(0, 0, 300, 300), mov);
//绘制电影纹理
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), mov, ScaleMode.StretchToFill);
if (GUILayout.Button("播放/继续"))
{
//播放/继续播放视频
if (!mov.isPlaying)
{
mov.Play();
}
}
if (GUILayout.Button("暂停播放"))
{
//暂停播放
mov.Pause();
}
if (GUILayout.Button("停止播放"))
{
//停止播放
mov.Stop();
}
}
}
以上是关于jquery怎么设置audio的loop的主要内容,如果未能解决你的问题,请参考以下文章