Php 在新数据库条目上播放声音
因此,我只发现了一个与我的问题相似的问题,而答案并没有真正帮助任何人,所以我希望用我自己的代码提问可以帮助我找到我正在寻找的答案 我想在发布新帖子时为我的shoutbox添加声音。我相信play sound函数将要用到的代码片段就在这里Php 在新数据库条目上播放声音,php,sql,ajax,jquery,Php,Sql,Ajax,Jquery,因此,我只发现了一个与我的问题相似的问题,而答案并没有真正帮助任何人,所以我希望用我自己的代码提问可以帮助我找到我正在寻找的答案 我想在发布新帖子时为我的shoutbox添加声音。我相信play sound函数将要用到的代码片段就在这里 function shouts() { clearTimeout(getshout); var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequ
function shouts() {
clearTimeout(getshout);
var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET", "shoutbox/shouts.php?i=" + Math.random());
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (parseInt(this.responseText) > current_shouts) {
getshouts();
current_shouts = parseInt(this.responseText);
}
getshout = setTimeout("shouts()", 1000);
}
}
xmlHttp.send(null);
}
但是我不是100%确定,我知道这是它检查数据库中新条目的地方,这个函数调用的相应php代码是
<?php
require_once("../config.php");
echo implode(mysql_fetch_assoc(mysql_query("SELECT COUNT(id) FROM shout")));
?>
我非常确信,要做到这一点,不必触碰这段代码。我在谷歌上做过搜索,也检查过多个论坛,但我还没有找到一种真正有效的方法,我不是要求你们帮我写代码,只要给我一个正确的方向
如果还有什么需要,请让我知道,我会编辑我的文章
谢谢,凯西你页面上的某个地方有
<audio id="myaudio" src="shout.mp3"></audio>
继续Eugene的帖子,编辑将回复添加到mysql数据库的php文件并播放音乐。我会调用
audio.play()
insidegetshouts()
请记住,音频标签仅在最新浏览器上受支持。查看此页面,了解音频标签的回退机制:
HTML
这段代码没有经过测试,但会给你一个基本的想法
更多资源:
干杯 我的设计是显示单行MySQL表中的声音文件名,并为用户提供播放它们的选项。列名表示促成最终应用程序中声音播放的事件。以下是PHP代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Event Sounds</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<h1><b>AZ Science Bowl</b> -- Back Room Operations</h1>
<h2>Event Sounds Selected -- and Test Play</h2>
<?php
$dsn = "mysql:dbname=SciBwl_Operation_TestI";
$username = "********";
$password = "********";
try {
$conn = new PDO( $dsn, $username, $password );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch ( PDOException $e ) {
echo "Connection failed: " . $e->getMessage();
}
$sql = "SELECT * FROM SoundsSelect";
echo "<ul>";
try {
$rows = $conn->query( $sql );
foreach ( $rows as $row ) {
echo "<li>For <b>Program Start:</b> " . $row["ProgStart"] . "\t<audio controls><source src=\"./sounds/" . $row["ProgStart"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>Break & Round Start:</b> " . $row["BrkRndStart"] . "\t<audio controls><source src=\"./sounds/" . $row["BrkRndStart"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>Toss & Bonus Start:</b> " . $row["TossBonusStart"] . "\t<audio controls><source src=\"./sounds/" . $row["TossBonusStart"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>5 Second Warning:</b> " . $row["5SecWarn"] . "\t<audio controls><source src=\"./sounds/" . $row["5SecWarn"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>Toss & Bonus End:</b> " . $row["TossBonusEnd"] . "\t<audio controls><source src=\"./sounds/" . $row["TossBonusEnd"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>30 Second End of Break Warning:</b> " . $row["30SecWarn"] . "\t<audio controls><source src=\"./sounds/" . $row["30SecWarn"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>Round End:</b> " . $row["RoundEnd"] . "\t<audio controls><source src=\"./sounds/" . $row["RoundEnd"] . "\" type=\"audio/wav\"></audio></li>";
}
} catch ( PDOException $e ) {
echo "Query failed: " . $e->getMessage();
}
echo "</ul>";
$conn = null;
?>
<br><br>
</body>
</html>
事件声音
AZ科学碗——后台操作
已选择事件声音--并测试播放
这种方法破坏了代码,我用几种方法实现了它,它阻止了shoutbox为其他用户加载新帖子。不太确定我做错了什么:/victmo的帖子让我能够以正确的方式实现它!我不知道你的意思是什么,我会在文件中添加什么,将文件实际发布到数据库,使其播放声音o.OI我很高兴你发布了这个,我无法实现它,但它让我对如何处理Eugen发布的代码有了更多的了解!非常感谢,我会给这个有用的凹凸,只要我有足够的重复
<audio id="audioplayer" preload>
<source src="audio.mp3">
</audio>
var audioTag = document.createElement('audio');
if (!(!!(audioTag.canPlayType) && ("no" != audioTag.canPlayType("audio/mpeg")) && ("" != audioTag.canPlayType("audio/mpeg")))) {
AudioPlayer.embed("audioplayer", {soundFile: "audio.mp3"});
}
function getshouts(){
... // your code
if(success){
audioTag.play();
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Event Sounds</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<h1><b>AZ Science Bowl</b> -- Back Room Operations</h1>
<h2>Event Sounds Selected -- and Test Play</h2>
<?php
$dsn = "mysql:dbname=SciBwl_Operation_TestI";
$username = "********";
$password = "********";
try {
$conn = new PDO( $dsn, $username, $password );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch ( PDOException $e ) {
echo "Connection failed: " . $e->getMessage();
}
$sql = "SELECT * FROM SoundsSelect";
echo "<ul>";
try {
$rows = $conn->query( $sql );
foreach ( $rows as $row ) {
echo "<li>For <b>Program Start:</b> " . $row["ProgStart"] . "\t<audio controls><source src=\"./sounds/" . $row["ProgStart"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>Break & Round Start:</b> " . $row["BrkRndStart"] . "\t<audio controls><source src=\"./sounds/" . $row["BrkRndStart"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>Toss & Bonus Start:</b> " . $row["TossBonusStart"] . "\t<audio controls><source src=\"./sounds/" . $row["TossBonusStart"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>5 Second Warning:</b> " . $row["5SecWarn"] . "\t<audio controls><source src=\"./sounds/" . $row["5SecWarn"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>Toss & Bonus End:</b> " . $row["TossBonusEnd"] . "\t<audio controls><source src=\"./sounds/" . $row["TossBonusEnd"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>30 Second End of Break Warning:</b> " . $row["30SecWarn"] . "\t<audio controls><source src=\"./sounds/" . $row["30SecWarn"] . "\" type=\"audio/wav\"></audio></li>";
echo "<li>For <b>Round End:</b> " . $row["RoundEnd"] . "\t<audio controls><source src=\"./sounds/" . $row["RoundEnd"] . "\" type=\"audio/wav\"></audio></li>";
}
} catch ( PDOException $e ) {
echo "Query failed: " . $e->getMessage();
}
echo "</ul>";
$conn = null;
?>
<br><br>
</body>
</html>