我正在开发一个健全的JavaScript库。我可以用下面的代码播放声音。
var soundPlayer = null;
function playSound(){
soundPlayer = new Audio(soundName).play();
}
如何停止和暂停此音频?当我这样做时:
soundPlayer.pause();
或者
soundPlayer.stop();
但是我收到了这个错误:
Uncaught TypeError: soundPlayer.stop is not a function
我该怎么做?
答案 0 :(得分:5)
如果你改变了:
soundPlayer = new Audio(soundName);
soundPlayer.play();
对此:
soundPlayer.pause();
soundPlayer.currentTime = 0;
你的停顿会有效。问题是你分配了#34; play"功能到soundPlayer。 SoundPlayer现在不是Audio对象。
而不是停止()使用:
BufferedImage image = ImageIO.read(new File("QRCode-1.png"));
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(image)));
Reader reader = new QRCodeReader();
Result result = reader.decode(binaryBitmap);
System.out.println("text: " + result.getText());
ResultPoint[] resultPoints = result.getResultPoints();
System.out.println("resultPoints:");
for (int i = 0; i < resultPoints.length; i++) {
ResultPoint resultPoint = resultPoints[i];
System.out.print(" [" + i + "]:");
System.out.print(" x = " + resultPoint.getX());
System.out.print(", y = " + resultPoint.getY());
if (resultPoint instanceof FinderPattern)
System.out.print(", estimatedModuleSize = "
+ ((FinderPattern) resultPoint).getEstimatedModuleSize());
System.out.println();
}
我认为它的工作方式相同。