添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
憨厚的熊猫  ·  uncaught ...·  2 年前    · 
风度翩翩的大海  ·  kubernetes - k8s:Get ...·  2 年前    · 
逆袭的墨镜  ·  springboot ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I want to implement audio-recorder, which I can start and stop by pressing the buttons. I have the following code of audio-recorder provided as an example in documentation of video-js-record:

<!doctype html>
  <meta charset="utf-8">
  <title>Audio/Video Example - Record Plugin for Video.js</title>
<link href="../../static/video.js/dist/video-js.min.css" rel="stylesheet">
    <link href="../../static/videojs-wavesurfer/dist/css/videojs.wavesurfer.min.css" rel="stylesheet">
  <link href="../../static/videojs-record/dist/css/videojs.record.css" rel="stylesheet">
  <link href="../../static/videojs-record/example.css" rel="stylesheet">
  <script src="../../static/video.js/dist/video.min.js"></script>
  <script src="../../static/recordrtc/RecordRTC.js"></script>
  <script src="../../static/webrtc-adapter/out/adapter.js"></script>
  <script src="../../static/wavesurfer.js/dist/wavesurfer.min.js"></script>
  <script src="../../static/wavesurfer.js/dist/plugin/wavesurfer.microphone.min.js"></script>
  <script src="../../static/videojs-wavesurfer/dist/videojs.wavesurfer.min.js"></script>
  <script src="../../static/videojs-record/dist/videojs.record.js"></script>
 <script src="../../static/browser_workround.js"></script>
  <style>
  /* change player background color */
  #myAudio {
      background-color: #9FD6BA;
  </style>
</head>
<audio id="myAudio" class="video-js vjs-default-skin"></audio>
<script>
/* eslint-disable */
var options = {
    controls: true,
    bigPlayButton: false,
    width: 600,
    height: 300,
    fluid: false,
    plugins: {
        wavesurfer: {
            backend: 'WebAudio',
            waveColor: '#36393b',
            progressColor: 'black',
            displayMilliseconds: true,
            debug: true,
            cursorWidth: 1,
            hideScrollbar: true,
            plugins: [
                // enable microphone plugin
                WaveSurfer.microphone.create({
                    bufferSize: 4096,
                    numberOfInputChannels: 1,
                    numberOfOutputChannels: 1,
                    constraints: {
                        video: false,
                        audio: true
        record: {
            audio: true,
            video: false,
            audioMimeType: `audio/wav`,
            maxLength: 20,
            displayMilliseconds: true,
            debug: true
// apply audio workarounds for certain browsers
applyAudioWorkaround();
// create player
var player = videojs('myAudio', options, function() {
    // print version information at startup
    var msg = 'Using video.js ' + videojs.VERSION +
        ' with videojs-record ' + videojs.getPluginVersion('record') +
        ', videojs-wavesurfer ' + videojs.getPluginVersion('wavesurfer') +
        ', wavesurfer.js ' + WaveSurfer.VERSION + ' and recordrtc ' +
        RecordRTC.version;
    videojs.log(msg);
// error handling
player.on('deviceError', function() {
    console.log('device error:', player.deviceErrorCode);
player.on('error', function(element, error) {
    console.error(error);
// user clicked the record button and started recording
player.on('startRecord', function() {
    console.log('started recording!');
// user completed recording and stream is available
player.on('finishRecord', function() {
    // the blob object contains the recorded data that
    // can be downloaded by the user, stored on server etc.
    console.log('finished recording: ', player.recordedData);
</body>
</html>
This code is working for me, but I need to start/stop without video-js interface. The following js code with html-buttons I wrote to trigger stop/start:
<script>
player.on('stopRecord', () => {
  console.log('stopped recording: ', player.record().recordedData); #this prints undefined
function startRecording(){
        player.record().getDevice();
        player.record().start(); # this one returns an error
function stopRecording(){
    player.record().stop();
</script>
<button onclick="play()" class="btn btn-primary">Play</button>
<button onclick="startRecording()" class="btn btn-primary">Start</button>
 <button onclick="stopRecording()" class="btn btn-warn">Stop</button>

player.record().getDevice() does exactly same as pressing the mic button in video-js interface - it starts the device. The problem is that when I call player.record().start() it somehow starts the timer on video-js interface but at the same time returns an error in console : videojs.record.js:3637 Uncaught TypeError: Cannot read properties of undefined (reading 'start') and I also don't see the starting message as if I'd press it on default interface. Pressing "stop" button stops the timer but player.record().recordedData is underfined. What am I doing wrong?

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.