apiCloud cyberplayer控制视频播放时间如果不是会员试看5分钟

风流意气都作罢 提交于 2020-02-27 23:53:38

html

		    <div id="playercontainer"></div>

script

		apiready = function(){
		  bofang(api.pageParam.video)
		
		}
		//播放配置

  function bofang(url){
	player = cyberplayer("playercontainer").setup({
		width: api.winWidth,
		height: 200,
		file: url, // <—rtmp or flv直播地址
		fallbackfile: url, // <— 备用播放地址,为了手机上能进行直播,设置hls直播流
		controlbar: {
			barLogo: false,
			autostart: true
		},
		stretching: "uniform",
		volume: 100,
		controls: true,
		ak: "dfd6c7951d4c477bb2555496c8e97166" // 公有云平台注册即可获得accessKey
	});

	player.play();// 播放
	player.on('play', function (ret) {
	  // alert(player.currentTime())
	  var time = localStorage.getItem('user_time');
	  var user_id = localStorage.getItem('user_id');
	  var username = localStorage.getItem('user_name');
	  var timestamp = Date.parse(new Date())/1000;
		if(time>timestamp){
		  console.log("这是会员")
		}else{
		  alert("esle")
		  setTimeout(()=>{
			 player.pause()
		  },180000)
		  console.log("这是非会员只能试看五分钟")
		}

	});
	player.on('pause',function(ret){
	  var time = localStorage.getItem('user_time');
	  var user_id = localStorage.getItem('user_id');
	  var username = localStorage.getItem('user_name');
	  var timestamp = Date.parse(new Date())/1000;
	  if(user_id==0){
		api.alert({
			title: '温馨提示',
			msg: '请先登陆后使用',
		});
		api.openWin({
			name: 'login',
			url: './login.html',
			delay: 300
		});
		return;

	  }

	  if (time>timestamp) {

	  }else if (time<timestamp){
		if(time>0){
		  var dialogBox = api.require('dialogBox');
		  dialogBox.alert({
			  texts: {
				  content: '您的VIP会员已过期,请及时续费!',
				  leftBtnTitle: '在想想',
				  rightBtnTitle: '去开通'
			  },
			  styles: {
				  bg: '#fff',
				  w: 300,
				  content: {
					  color: '#000',
					  size: 14
				  },
				  left: {
					  marginB: 7,
					  marginL: 20,
					  w: 130,
					  h: 35,
					  corner: 2,
					  bg: '#ff7600',
					  color: '#fff',
					  size: 14
				  },
				  right: {
					  marginB: 7,
					  marginL: 10,
					  w: 130,
					  h: 35,
					  corner: 2,
					  bg: '#ff7600',
					  color: '#fff',
					  size: 14
				  }
			  }
		  }, function(ret) {
			  if (ret.eventType == 'left') {
				  var dialogBox = api.require('dialogBox');
				  dialogBox.close({
					  dialogName: 'alert'
				  });
			  }else if (ret.eventType == 'right') {
				api.openWin({
					name: 'open_vip_win',
					url: './open_vip_win.html',
					delay: 300
				});
				var dialogBox = api.require('dialogBox');
				dialogBox.close({
					dialogName: 'alert'
				});
			  }
		  });
		}else{
		  dialogBox.alert({
			  texts: {
				  content: '未登录!',
				  leftBtnTitle: '在想想',
				  rightBtnTitle: '去登录'
			  },
			  styles: {
				  bg: '#fff',
				  w: 300,
				  content: {
					  color: '#000',
					  size: 14
				  },
				  left: {
					  marginB: 7,
					  marginL: 20,
					  w: 130,
					  h: 35,
					  corner: 2,
					  bg: '#ff7600',
					  color: '#fff',
					  size: 14
				  },
				  right: {
					  marginB: 7,
					  marginL: 10,
					  w: 130,
					  h: 35,
					  corner: 2,
					  bg: '#ff7600',
					  color: '#fff',
					  size: 14
				  }
			  }
		  }, function(ret) {
			  if (ret.eventType == 'left') {
				  var dialogBox = api.require('dialogBox');
				  dialogBox.close({
					  dialogName: 'alert'
				  });
			  }else if (ret.eventType == 'right') {
				api.openWin({
					name: 'login',
					url: './login.html',
					delay: 300
				});
				var dialogBox = api.require('dialogBox');
				dialogBox.close({
					dialogName: 'alert'
				});
			  }
		  });
		}

	  }

	})


	player.on('fullscreen', function (ret) {
		 //alert( JSON.stringify( ret ) );
		 if (ret.fullscreen) {
		   api.setScreenOrientation({
			   orientation: 'landscape_right'
		   });
		 }else {
		   api.setScreenOrientation({
			   orientation: 'portrait_up'
		   });
		 }
	});
	// player.ready(function(){
	//   this.on('play',function(){
	//     alert(player.currentTime())
	//   })
	// })

	api.addEventListener({
		name: 'keyback'
	}, function(ret, err) {
	  api.setScreenOrientation({
		  orientation: 'portrait_up'
	  });
	  api.closeWin();
	});
  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!