如何使用空格键播放/暂停html5视频

时间:2014-11-17 20:07:28

标签: html5-video

如何使用e.key暂停空格键的html5视频?有关逻辑的事情......

    <div class=modal-video id="v-5417">
    <div class=video-player>
                    <video id=v-5417-tape preload="none">
                        <source type="video/mp4" src="videos/anthem-od47.mp4">
                        <source type="video/webm" src="videos/anthem-od47.webm">
                    </video>
                    <div class="close-modal fade-control"></div>
                </div>
            </div>

JS

$( document ).on( 'keydown', function ( e ) {
            if ( e.keyCode === 32 ) {
                if (video.paused == true) {
                    // Play the video
                    video.play();
                }else{
                    if(video.play == true){
                    video.pause();
                    }
                }
            }
        });

4 个答案:

答案 0 :(得分:6)

以下是您对javascript的更改:

&#13;
&#13;
$(window).keypress(function(e) {
  var video = document.getElementById("vid");
  if (e.which == 32) {
    if (video.paused)
      video.play();
    else
      video.pause();
  }
});
&#13;
&#13;
&#13;

答案 1 :(得分:1)

使用x_train = tokenizer.texts_to_sequences(train_df) x_test = tokenizer.texts_to_sequences(test_df) maxlen = 43036 vocab_size = len(tokenizer.word_index) + 1 x_train = pad_sequences(x_train, padding='post', maxlen=maxlen) x_test = pad_sequences(x_test, padding='post', maxlen=maxlen) mlb_label_train = MultiLabelBinarizer() y_train = mlb_label_train.fit(label_train.values) y_train_tags = mlb_label_train.fit_transform(label_train.values) mlb_label_test = MultiLabelBinarizer() y_test = mlb_label_test.fit(label_test.values) y_test_tags = mlb_label_test.fit_transform(label_test.values) model = Sequential() model.add(Embedding(input_dim=vocab_size, output_dim=200, input_length=maxlen)) model.add(Dropout(0.3)) model.add(Conv1D(filter_length, 3, padding='valid', activation='relu')) model.add(GlobalMaxPooling1D()) model.add(Dense(200)) model.add(Activation('sigmoid')) 可以停止将网页滚动到底部。

e.preventDefault()

答案 2 :(得分:0)

&#13;
&#13;
var videoPlayer = document.getElementById('Video1')
$(window).keypress(function(e) {
  if (e.keyCode == 0 || e.keyCode == 32) {
	if (videoPlayer.paused == false) {
            videoPlayer.pause();
            videoPlayer.firstChild.nodeValue = 'Play';
        } else {
            videoPlayer.play();
            videoPlayer.firstChild.nodeValue = 'Pause';
        }
  
  }
});
&#13;
<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
  <script src="/website/js/playPause.js></script>
</head>
<body>
  <center>
    <h1>Video</h1>
    <video id="Video1" autoplay="yes">
      <source src="videoName.mp4" type="video/mp4" />
    </video>
  </center>
</body>
</html>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

在这里,你应该这样做。

// Press spacebar to Play/Pause.
    var body = $( 'body' );

    body.keypress( function ( e ) {
        if ( e.which == 32 ) {
            // Stop the jerk.
            e.preventDefault();

            // If video is paused.
            if ( theVideo.get(0).paused == true ) {
                theVideo.get(0).play();
            } else {
                theVideo.get(0).pause();
            }
        }
    }); // End keypress().