视频错误-未捕获(承诺)DOMException:调用play()中断了play()请求

时间:2018-11-12 02:25:54

标签: javascript html html5 object ecmascript-6

我最近购买了带有内置广告系统的视频脚本。看起来工作还不错。我可以动态添加各种​​类型的广告,等等。但是,播放我的一个视频时出现了问题。视频文件在Windows中可以正常播放,在Chrome和Edge中也可以正常播放。使用原生HTML5视频播放器以及video.js,它也可以正常播放。当我切换到这个新脚本时,我测试了所有视频,发现以前播放过的一个视频不再播放。

在Google控制台中,它提供了一条消息:“未捕获(承诺)DOMException:play()请求被调用pause()中断了。”

与我使用的其他视频播放器不同,此播放器的所有HTML标记都是由js文件生成的,该js文件从动态生成的div中获取视频文件位置,拇指位置,广告位置/时间等,等

我已经研究了很多有关此问题的方法,但似乎无法弄清楚问题是什么。请看一下代码,让我知道是否有人看到任何突出的内容。提前致谢!哦,我应该说,除了这部新影片以外,所有其他影片都可以使用。

注意:由于JS文件的行数超过30万,因此我无法在此消息区域中包含它,但是您可以在此处查看JS文件:https://www.stoners.org/videos/java/vplayer.unmin.js

我以此初始化播放器:

<script src="/videos/java/vplayer.unmin.js" type="text/javascript"></script>
<script type="text/javascript">

    FWDUVPUtils.onReady(function(){

        new FWDUVPlayer({       


        //main settings
        instanceName:"player1",
        parentId:"myDiv",
        playlistsId:"playlists",
        mainFolderPath:"content",
        skinPath:"minimal_skin_dark",
        displayType:"responsive",
        initializeOnlyWhenVisible:"no",
        useFontAwesomeIcons:"no",
        fillEntireVideoScreen:"no",
        useHEXColorsForSkin:"no",
        normalHEXButtonsColor:"#FF0000",
        selectedHEXButtonsColor:"#000000",
        useDeepLinking:"yes",
        rightClickContextMenu:"default",
        addKeyboardSupport:"yes",
        showPreloader:"yes",
        preloaderColors:["#999999", "#FFFFFF"],
        autoScale:"yes",
        showButtonsToolTip:"yes", 
        stopVideoWhenPlayComplete:"no",
        playAfterVideoStop:"no",
        autoPlay:"yes",
        loop:"no",
        shuffle:"no",
        showErrorInfo:"yes",
        maxWidth:980,
        maxHeight:552,
        buttonsToolTipHideDelay:1.5,
        volume:.8,
        backgroundColor:"#000000",
        videoBackgroundColor:"#000000",
        posterBackgroundColor:"#000000",
        buttonsToolTipFontColor:"#5a5a5a",
        //logo settingscate
        showLogo:"yes",
        hideLogoWithController:"no",
        logoPosition:"topRight",
        logoLink:"https://www.stoners.org/videos",
        logoMargins:5,
        //playlists/categories settings
        showPlaylistsSearchInput:"no",
        usePlaylistsSelectBox:"no",
        showPlaylistsButtonAndPlaylists:"no",
        showPlaylistsByDefault:"no",
        thumbnailSelectedType:"opacity",
        startAtPlaylist:0,
        buttonsMargins:0,
        thumbnailMaxWidth:350, 
        thumbnailMaxHeight:350,
        horizontalSpaceBetweenThumbnails:40,
        verticalSpaceBetweenThumbnails:40,
        inputBackgroundColor:"#333333",
        inputColor:"#999999",
        //playlist settings
        showPlaylistButtonAndPlaylist:"no",
        playlistPosition:"right",
        showPlaylistByDefault:"yes",
        showPlaylistName:"yes",
        showSearchInput:"no",
        showLoopButton:"yes",
        showShuffleButton:"yes",
        showNextAndPrevButtons:"yes",
        showThumbnail:"yes",
        forceDisableDownloadButtonForFolder:"yes",
        addMouseWheelSupport:"yes",
        startAtRandomVideo:"no",
        stopAfterLastVideoHasPlayed:"no",
        folderVideoLabel:"VIDEO ",
        playlistRightWidth:310,
        playlistBottomHeight:599,
        startAtVideo:0,
        maxPlaylistItems:50,
        thumbnailWidth:70,
        thumbnailHeight:70,
        spaceBetweenControllerAndPlaylist:2,
        spaceBetweenThumbnails:2,
        scrollbarOffestWidth:8,
        scollbarSpeedSensitivity:.5,
        playlistBackgroundColor:"#000000",
        playlistNameColor:"#FFFFFF",
        thumbnailNormalBackgroundColor:"#1b1b1b",
        thumbnailHoverBackgroundColor:"#313131",
        thumbnailDisabledBackgroundColor:"#272727",
        searchInputBackgroundColor:"#000000",
        searchInputColor:"#999999",
        youtubeAndFolderVideoTitleColor:"#FFFFFF",
        folderAudioSecondTitleColor:"#999999",
        youtubeOwnerColor:"#888888",
        youtubeDescriptionColor:"#888888",
        mainSelectorBackgroundSelectedColor:"#FFFFFF",
        mainSelectorTextNormalColor:"#FFFFFF",
        mainSelectorTextSelectedColor:"#000000",
        mainButtonBackgroundNormalColor:"#212021",
        mainButtonBackgroundSelectedColor:"#FFFFFF",
        mainButtonTextNormalColor:"#FFFFFF",
        mainButtonTextSelectedColor:"#000000",
        //controller settings
        showController:"yes",
        showControllerWhenVideoIsStopped:"yes",
        showNextAndPrevButtonsInController:"no",
        showRewindButton:"yes",
        showPlaybackRateButton:"yes",
        showVolumeButton:"yes",
        showTime:"yes",
        showQualityButton:"yes",
        showInfoButton:"no",
        showDownloadButton:"no",
        showFacebookButton:"yes",
        showEmbedButton:"yes",
        showFullScreenButton:"yes",
        disableVideoScrubber:"no",
        showDefaultControllerForVimeo:"no",
        repeatBackground:"yes",
        controllerHeight:37,
        controllerHideDelay:3,
        startSpaceBetweenButtons:7,
        spaceBetweenButtons:8,
        scrubbersOffsetWidth:2,
        mainScrubberOffestTop:14,
        timeOffsetLeftWidth:5,
        timeOffsetRightWidth:3,
        timeOffsetTop:0,
        volumeScrubberHeight:80,
        volumeScrubberOfsetHeight:12,
        timeColor:"#888888",
        youtubeQualityButtonNormalColor:"#888888",
        youtubeQualityButtonSelectedColor:"#FFFFFF",
        //advertisement on pause window
        aopwTitle:"Sponsor",
        aopwWidth:400,
        aopwHeight:240,
        aopwBorderSize:6,
        aopwTitleColor:"#FFFFFF",
        //subtitle
        subtitlesOffLabel:"Subtitle off",
        //popup add windows
        showPopupAdsCloseButton:"yes",
        //embed window and info window
        embedAndInfoWindowCloseButtonMargins:0,
        borderColor:"#333333",
        mainLabelsColor:"#FFFFFF",
        secondaryLabelsColor:"#a1a1a1",
        shareAndEmbedTextColor:"#5a5a5a",
        inputBackgroundColor:"#000000",
        inputColor:"#FFFFFF",
        //audio visualizer
        audioVisualizerLinesColor:"#0099FF",
        audioVisualizerCircleColor:"#FFFFFF",
        //lightbox settings
        lightBoxBackgroundOpacity:.6,
        lightBoxBackgroundColor:"#000000",
        //sticky display settings
        showOpener:"yes",
        showOpenerPlayPauseButton:"yes",
        verticalPosition:"bottom",
        horizontalPosition:"center",
        showPlayerByDefault:"yes",
        animatePlayer:"yes",
        openerAlignment:"right",
        mainBackgroundImagePath:"https://www.stoners.org/videos/content/minimal_skin_dark/main-background.png",
        openerEqulizerOffsetTop:-1,
        openerEqulizerOffsetLeft:3,
        offsetX:0,
        offsetY:0,
        //loggin
        isLoggedIn:"no",
        playVideoOnlyWhenLoggedIn:"no",
        loggedInMessage:"Please login to view this video.",
        //playback rate / speed
        defaultPlaybackRate:1, //0.25, 0.5, 1, 1.25, 1.2, 2
        //cuepoints
        executeCuepointsOnlyOnce:"no",
        //ads
        openNewPageAtTheEndOfTheAds:"no",
        playAdsOnlyOnce:"no",
        adsButtonsPosition:"right",
        skipToVideoText:"You can skip ad in: ",
        skipToVideoButtonText:"Skip Ad",
        adsTextNormalColor:"#888888",
        adsTextSelectedColor:"#FFFFFF",
        adsBorderNormalColor:"#666666",
        adsBorderSelectedColor:"#FFFFFF"

        });

    });

</script>

通过以下操作,您可以看到它在播放器中不起作用: https://www.stoners.org/videos/profiles/9/weed-truffles-75mg#/?playlistId=0&videoId=0

您可以直接访问以下视频文件,以查看该文件是否可以在Chrome,Windows等操作系统中打开:https://www.stoners.org/videos/library/1527856863.mp4

请让我知道我是否可以提供其他帮助以解决问题所在。赞赏!

2 个答案:

答案 0 :(得分:1)

我设法通过使用以下代码解决了这个问题:

function fix(item) {
    var thePromise = item.play();

    if (thePromise != undefined) {

        thePromise.then(function(_) {

            item.pause();
            item.currentTime = 0;

        });

    }
}

只需使用您拥有的任何音频/视频执行该操作,它将停止发出该错误。

答案 1 :(得分:0)

太好了!杰克·巴什福德(Jack Bashford)的修复工作成功了。

我在“革命滑块”中添加了一个视频,只要该幻灯片可见,就需要播放该视频:

HTML标记:

<div class="tp-caption" data-x="center" data-y="0" data-speed="1500" data-start="500">
        <video id="xxx" title="xxx" webkit-playsinline="true" autoplay="true" muted="muted" preload="auto"  controls="false" playsinline="true">
        <source src="file"  type='video/mp4;  codecs="avc1.42E01E, mp4a.40.2"'>
        </video>
      </div>

JavaScript及其修复:

		jQuery(document).ready(function() {
			$('.owl-carousel').owlCarousel();
			App.init();
			// RevolutionSlider.initRSfullWidth();
			
			var revapi;
			revapi = jQuery('.tp-banner').revolution(
			{
				delay:5500,
				startwidth:1170,
				startheight:600,
				hideThumbs:10,
				navigationType:'none',
				navigationStyle:'square',
				navigationHAlign:'center',
				navigationVAlign:'bottom',
				navigationArrows:'none',
				onHoverStop: 'off',
				navigation: {
					onHoverStop: 'off'
				}
			});
			
			revapi.on('revolution.slide.onchange', function(event, data) {

				console.log("Current Slide: "+data.slideIndex);

				if(data.slideIndex==2) {
					console.log("Play the video v2");
					var vid = document.getElementById("fiveyears");
					vid.controls = false;
					var thePromise = vid.play();
					if (thePromise != undefined) {
						console.log("Caught Promise Error");
						thePromise.then(function(_) {
							vid.pause();
							vid.currentTime = 0;
							vid.play();
						});
					} else {
						vid.play();
					}
					vid.controls = false;
				}
			});
			
			
		});