只播放声音

时间:2015-08-18 16:09:30

标签: javascript html5

我正在制作一个小型小行星避免游戏,当我的生命结束时,我正在执行以下代码:

gameover.play();

虽然gameover定义如下:

var gameover = new Audio('gameover.wav');

当我执行代码时,它会循环播放声音,我只想播放一次,我该怎么做?感谢。

1 个答案:

答案 0 :(得分:3)

我相信将loop属性设置为var products = new kendo.data.Model.define({ id: "ID", fields: { ID: { editable: false, type: "number" }, ProductID: { type: "number", nullable: false, editable: true }, Quantity: { type: "number", nullable: false, editable: true }, Description: { type: "string" }, UnitPrice: { type: "number" }, TotalPrice: { type: "number" }, WorkText: { type: "string" }, CreatedDateTime: { type: "date" } } }); var dataSource = new kendo.data.DataSource({ transport: { read: { url: "/Service/ProductsReadTicket", dataType: "json" }, update: { url: "/Service/ProductsUpdateTicket", dataType: "json", contentType: "application/json" }, create: { url: "/Service/ProductsCreateTicket", dataType: "json", contentType: 'application/json; charset=utf-8' }, parameterMap: function (options, operation) { if (operation !== "read" && options.models) { return { model: options.models }; } if (operation == "read") { return { ticketid: iidee }; } } }, batch: true, pageSize: 20, schema: { model: products, data: function (data) { return data.Data; } } }); $("#grid3").kendoGrid({ toolbar: ["create", "save", "cancel"], dataSource: dataSource, sortable: true, autobind: false, pageable: true, selectable: true, filterable: true, columns: [ { field: "ID", title: "ID", hidden: true }, { field: "CreatedDateTime", title: "Pvm", format: "{0:dd.MM.yyyy HH:mm}" }, { field: "ProductID", title: "Tuotenro" }, { field: "Description", title: "Nimi" }, { field: "WorkText", title: "Teksti" }, { field: "Quantity", title: "Määrä" }, { field: "UnitPrice", title: "Hinta" }, { field: "TotalPrice", title: "Kokonaishinta" }, ], editable: true }); 即可实现目标。

false



var birdSound = new Audio('http://www.noiseaddicts.com/samples_1w72b820/4929.mp3');
birdSound.loop = false;
birdSound.play();

var birdSound = new Audio('http://www.noiseaddicts.com/samples_1w72b820/4929.mp3');
birdSound.loop = false;
birdSound.play();

var statusElem = document.getElementById('status');
var startTime = Date.now();
updateStatus();

function updateStatus(){
  if (birdSound.ended){
    statusElem.innerText = 'Stopped';
  } else {
    statusElem.innerText = 'Playing (' + ( ( Date.now() - startTime ) / 1000 )  + ')';
    window.setTimeout(updateStatus, 50);
  }
}




测试:

  • Chrome 44.0.2403.155(64位)
  • Firefox 40.0.2
  • Safari 8.0.6
  • Vivaldi 1.0.94.2 (giggles)