首页 > 代码库 > 声音播放
声音播放
function () { $(‘.audio‘).each(function () { var $this = $(this); var id = $this.attr(‘audioid‘); var src = http://www.mamicode.com/$this.attr(‘src‘);"btn-group audio-control"> <button type="button" class="btn btn-default btn-repeat"><span class="glyphicon glyphicon-repeat"></span></button> <button type="button" class="btn btn-default btn-play"><span class="glyphicon glyphicon-play"></span></button> <button type="button" class="btn btn-default btn-pause"><span class="glyphicon glyphicon-pause"></span></button> <button class="btn btn-default" disabled="disabled"> <div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:0;"> <span class="sr-only">60% Complete</span> </div> </div> </button> <button class="btn btn-default btn-size" disabled="disabled"></button></div>‘); var width = (soundsize < 20 ? 20 : soundsize > 60 ? 60 : soundsize) * 300 / 60; $this.find(‘.progress‘).width(width); var $btnplay = $this.find(‘.btn-play‘); var $btnpause = $this.find(‘.btn-pause‘).hide(); var $btnrepeat = $this.find(‘.btn-repeat‘); var $btnsize = $this.find(‘.btn-size‘).text(soundsize + ‘s‘); var $audio = $this.find(‘audio‘); var $progressbar = $this.find(‘.progress-bar‘); $btnplay.bind(‘click‘, function () { if (!$audio.attr(‘src‘)) { $.ajax({ url: ‘Sound.ashx‘, data: { id: id, url: src }, dataType: ‘json‘, type: ‘POST‘, success: function (data, textStatus, jqXHR) { // 加载音频文件 if ($audio.attr(‘src‘) != data.url) { $audio.bind({ ‘canplaythrough‘: function () { //alert(‘音频文件已经准备好,随时待命‘); this.volume = 1; this.play(); }, ‘timeupdate‘: function () { // 跟踪进度 var duration = this.duration; var currentTime = this.currentTime; $progressbar.width((currentTime / this.duration) * width); }, ‘pause‘: function () { $btnplay.show(); $btnpause.hide(); }, ‘ended‘: function () { $btnplay.show(); $btnpause.hide(); }, ‘playing‘: function () { $btnplay.hide(); $btnpause.show(); } }); $audio.attr(‘src‘, data.url); } } }); } else { $audio[0].play(); } }); $btnpause.bind(‘click‘, function () { $audio[0].pause(); }); $btnrepeat.bind(‘click‘, function () { $audio[0].currentTime = 0; $audio[0].play(); ; }); })public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; // 下载音频文件 var id = context.Request["id"]; var url = context.Request["url"]; // 判断文件是否存在 var filepath = "/Audio/" + id + ".mp3"; if (System.IO.File.Exists(context.Server.MapPath(filepath))) { context.Response.Write("{\"url\":\"" + filepath + "\"}"); return; } HttpPost clientContext = new HttpPost(url); var data = http://www.mamicode.com/clientContext.GetBytes();"~/Audio/ffmpeg.exe") , context.Server.MapPath("~/temp/") , context.Server.MapPath(filepath) , SpeexDecoderType.MP3); context.Response.Write("{\"url\":\"" + filepath + "\"}"); return; //context.Response.Redirect("~/Audio/" + filename); } catch (Exception) { } //context.Response.Write("Hello World"); }
声音播放
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。