Skip to content

Commit

Permalink
feat: 音频测试
Browse files Browse the repository at this point in the history
  • Loading branch information
wang1xiang authored and 王翔 committed Aug 3, 2023
0 parents commit 4260356
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## WebRTC DEMO
12 changes: 12 additions & 0 deletions audio/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>音频测试</title>
</head>
<body>
<audio id="audio" controls autoplay></audio>
<script src="./main.js"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions audio/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const audioDOM = document.querySelector('#audio')

const onSuccess = (stream) => {
const audioTracks = stream.getAudioTracks()
console.log('音频设备: ' + audioTracks[0].label)
// 播放音频轨道获取的流
audioDOM.srcObject = stream
}

const onError = (error) => console.log(error)

const constraints = {
audio: true,
video: false,
}
// 访问媒体设备
navigator.mediaDevices
.getUserMedia(constraints)
.then(onSuccess)
.catch(onError)

0 comments on commit 4260356

Please sign in to comment.