forked from wang1xiang/webrtc-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4260356
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## WebRTC DEMO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |