YouTube IFrame API ,再生リストの動作確認、
以前に作成したプログラムは正常に停止しない、再び最初から
再生が始まります。そのための確認です。
今回のストップボイントは下記となります、各event.コード発生時に
実行します。
function stop(event){
if(event.target.getPlaylist()){
if(event.target.getVideoData().video_id == event.target.getPlaylist()[event.target.getPlaylist().length -1]) {
event.target.stopVideo();
}else{
event.target.playVideo();
}
}
}
<!DOCTYPE html>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// YouTube Player API Reference for iframe Embeds
// https://developers.google.com/youtube/iframe_api_reference
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '0',
width: '0',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError' : onPlayerError,
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
console.log(event.target.getPlayerState());
player.cuePlaylist({list:'PLoxAMAuDB1YbftJRZtIlec92SFNAPTnjW'});
event.target.playVideo();
}
function onPlayerStateChange(event) {
console.log('event.target.getPlayerState()' + event.target.getPlayerState());
console.log('event.data' + event.data);
console.log('player.getPlaylistId()' + event.target.getPlaylistId());
console.log('player.getPlaylist()' + event.target.getPlaylist());
console.log('player.getPlaylistIndex()' + event.target.getPlaylistIndex());
if(event.target.getPlayerState() == 5){
stop(event);
console.log('5---' + event.target.getPlayerState());
}
if(event.target.getPlayerState() == 4){
stop(event);
console.log('4---' + event.target.getPlayerState());
}
if(event.target.getPlayerState() == 3){
stop(event);
console.log('3---' + event.target.getPlayerState());
}
if(event.target.getPlayerState() == 2){
stop(event);
console.log('2---' + event.target.getPlayerState());
}
if(event.target.getPlayerState()== 1){
stop(event);
console.log('1---' + event.target.getPlayerState());
//event.target.nextVideo();
}
if(event.target.getPlayerState() == 0){
stop(event);
console.log('0--' + event.target.getPlayerState());
}
if(event.target.getPlayerState() == -1){
console.log('-1--' + event.target.getPlayerState());
}
}
function onPlayerError(event){
if(event.target.getPlaylist()){
if(event.target.getVideoData().video_id == event.target.getPlaylist()[event.target.getPlaylist().length -1]) {
event.target.stopVideo();
}else{
event.target.nextVideo();
}
}
}
function stop(event){
if(event.target.getPlaylist()){
if(event.target.getVideoData().video_id == event.target.getPlaylist()[event.target.getPlaylist().length -1]) {
event.target.stopVideo();
}else{
event.target.playVideo();
}
}
}
function stop_play() {
console.log(event.target.getPlayerState());
player.stopVideo();
}
//player.cuePlaylist({list:'PLoxAMAuDB1YbftJRZtIlec92SFNAPTnjW'});
</script>
</body>
</html>
2016年1月27日水曜日
2016年1月23日土曜日
addEventListener 一覧
分類 | イベントハンドラ | 発生状況 |
---|---|---|
onload | リソースのロードが完了したとき | |
onunload | アンロードされたとき (ロードする前) | |
readystatechange | documentのreadyState属性が変化したとき | |
フォーカス | onfocus | 要素が入力フォーカスを得たとき |
onblur | 要素が入力フォーカスを失ったとき | |
onchange | ユーザーが要素の値を変更し、要素が入力フォーカスを失ったとき (プログラムから変更した場合には、イベントは発生しない) | |
onselect | テキストが選択されたとき | |
oncontextmenu | マウスで右クリック、またはアプリケーションキーが押されるなどして、コンテキストメニューが表示されるとき | |
マウス | onclick | マウスでクリックされたとき |
ondblclick | マウスでダブルクリックされたとき | |
onmousedown | マウスボタンが押されたとき | |
onmouseup | マウスボタンが離されたとき | |
onmouseover | マウスが要素に乗ったとき | |
onmouseout | マウスが要素から離れたとき | |
onmousemove | マウスが要素の上を移動したとき | |
キー | onkeydown | ユーザーがキーを押したとき |
onkeypress | ユーザーがキーを押して離したとき | |
onkeyup | ユーザーがキーを離したとき | |
フォーム | onsubmit | フォームの送信が要求されたとき |
onreset | フォームのリセットが要求されたとき | |
onresize | ウィンドウのサイズが変更されたとき (Windowオブジェクトのみ) | |
onscroll | 要素のコンテンツがスクロールされたとき | |
onabort | 画像のロードが中断されたとき | |
onerror | 画像のロード中にエラーが発生したとき |
ラベル:
addEventListener,
Javascript
2016年1月20日水曜日
テキストボックスのオートコンプリートを無効
テキストボックスのオートコンプリートを無効
autocomplete="off"
<input type="text" name="input" autocomplete="off" />
autocomplete="off"
<input type="text" name="input" autocomplete="off" />
2016年1月18日月曜日
フォームの送信(onsubmit)を中断する
submitの送信を中断する、addEventListener エベントの戻り値。
送信する値は””であれば、送信しませんん。
<php
echo "<form action =\"{$action_url}\" id =\"f\" method = \"get\">";
echo "<input id = \"searchform_q\" name = \"search_query\" value = \"{$value}\">";
echo '<button id = "searchform_button">send</button>';
echo '</from>';
?>
<script type = "text/javascript">
addevt();
function addevt(){
var f = document.getElementById('f');
f.addEventListener("submit",button_chk,false);
}
function button_chk(){
var input_text = document.getElementById('searchform_q');
if(input_text.value == ""){
event.returnValue=false; <<event.returnValue
}else{
event.returnValue=true;
}
}
</script>
送信する値は””であれば、送信しませんん。
<php
echo "<form action =\"{$action_url}\" id =\"f\" method = \"get\">";
echo "<input id = \"searchform_q\" name = \"search_query\" value = \"{$value}\">";
echo '<button id = "searchform_button">send</button>';
echo '</from>';
?>
<script type = "text/javascript">
addevt();
function addevt(){
var f = document.getElementById('f');
f.addEventListener("submit",button_chk,false);
}
function button_chk(){
var input_text = document.getElementById('searchform_q');
if(input_text.value == ""){
event.returnValue=false; <<event.returnValue
}else{
event.returnValue=true;
}
}
</script>
2016年1月5日火曜日
SQLITE3利用したログ記録 その3
<?php
//logo
set_time_limit(120);
session_name('aixin');
session_start();
//error_reporting(E_ALL);
date_default_timezone_set('Asia/Tokyo');
//include_once('acclog.php');
$hi = new acclog();
if(count(get_included_files()) == 1){
if(array_key_exists('xx',$_GET)){
//$hi->viewlog();
$hi->viewlog2();
}else{
$name = basename(__FILE__);
echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
echo '<html><head>';
echo '<title>404 Not Found</title>';
echo '</head><body>';
echo '<h1>Not Found</h1>';
echo "<p>The requested URL /{$name} was not found on this server.</p>";
echo '</body></html>';
exit();
}
}
class acclog{
public $db_name = "acclog.db";
// select datetime(request_time,"localtime") from log;
public function acclog(){
if(!file_exists($this->db_name)){
$this->create_acclog_db();
}
if(filesize($this->db_name) > 6438912){
$this->diet();
}
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$temp = $db->prepare("insert into log ('remote_addr','http_user_agent','request_uri','http_accept_language') values (:a,:b,:c,:d)");
$temp->bindValue(':a',$_SERVER['REMOTE_ADDR'],SQLITE3_TEXT);
$temp->bindValue(':b',$this->user_agent($_SERVER['HTTP_USER_AGENT']),SQLITE3_TEXT);
$temp->bindValue(':c',$_SERVER['REQUEST_URI'],SQLITE3_TEXT);
$temp->bindValue(':d',$_SERVER['HTTP_ACCEPT_LANGUAGE'],SQLITE3_TEXT);
$temp->execute();
$db->close();
$this->page_count($_SERVER['SCRIPT_FILENAME']);
}
private function user_agent($agent){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$sql_select = sprintf("select rowid from user_agent where http_user_agent = \"%s\"",$agent);
$sql_insert = sprintf("insert into user_agent (http_user_agent) values (\"%s\")",$agent);
$temp = $db->querySingle($sql_select);
if(is_null($temp)){
$db->exec($sql_insert);
$temp = $db->querySingle($sql_select);
$db->close();
return $temp;
}else{
$db->close();
return $temp;
}
$db->close();
}
public function viewlog2(){
$db = new sqlite3($this->db_name);
$db->busyTimeout(1000);
$temp1 = $db->querySingle("select count(*) from log");
$temp2 = $db->querySingle("select count(*) from user_agent");
$temp3 = $db->querySingle("select count(*) from page_count");
$file_size = round((filesize($this->db_name)/1024/1024),2);
echo "<div>log_count:: {$temp1}</div>";
echo "<div>user_agent_count:: {$temp2}</div>";
echo "<div>page_count:: {$temp3}</div>";
echo "<div>file_size:: {$file_size} MB</div>";
echo '<br>';
$vt = $db->prepare("select * from page_count");
$vx = $vt->execute();
echo '<table border=1>';
while($vxx = $vx->fetchArray(SQLITE3_ASSOC)){
echo "<tr><td>{$vxx['script_filename']}</td><td>{$vxx['count']}</td></tr>";
}
echo '</table>';
$db->close();
}
public function viewlog(){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$temp = $db->prepare("select rowid,http_user_agent from user_agent order by http_user_agent asc");
$temp2 = $temp->execute();
while($temp3 = $temp2->fetchArray(SQLITE3_ASSOC)){
$temp4 = $this->user_agent_count($temp3['rowid']);
if($temp4 != 0){
echo "<div>{$temp3['rowid']}::{$temp3['http_user_agent']}</div>";
echo "<div>{$temp4}</div>";
echo "<div><br></div>";
}
}
$vt = $db->prepare("select * from page_count");
$vx = $vt->execute();
while($vxx = $vx->fetchArray(SQLITE3_ASSOC)){
echo "<div>[script_filename] => {$vxx['script_filename']}</div>";
echo "<div>[count] => {$vxx['count']}</div>";
}
$db->close();
}
private function user_agent_count($rowid){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$temp = $db->prepare("select count(*) as count from log where http_user_agent = :a");
$temp->bindValue(':a',$rowid);
$temp2 = $temp->execute();
while($temp3 = $temp2->fetchArray(SQLITE3_ASSOC)){
$db->close();
return $temp3['count'];
}
$db->close();
}
private function page_count($script_filename){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
//script_filename
$sql_1 = sprintf("select script_filename from page_count where script_filename = \"%s\"",$script_filename);
$sql_2 = sprintf("insert into page_count (script_filename,count) values (\"%s\",0)",$script_filename);
$sql_3 = sprintf ("update page_count set count = count + 1 where script_filename = \"%s\"",$script_filename);
$temp = $db->querySingle($sql_1);
if($temp == null){
$db->exec($sql_2);
$db->exec($sql_3);
}else{
$db->exec($sql_3);
}
$db->close();
}
private function diet(){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
//$temp = $db->prepare("delete from log where request_time < datetime('now','-2 days')");
//$temp->execute();
$sql = sprintf("delete from log where request_time < datetime('now','-1 days')");
$db->exec($sql);
$db->exec('VACUUM');
$db->close();
}
public function create_acclog_db(){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$create_db =
"create table log(
request_time text default current_timestamp,
remote_addr text,
http_user_agent text,
request_uri text,
http_accept_language text
)";
$db->exec($create_db);
$create_db =
"create table user_agent(
http_user_agent text
)";
$db->exec($create_db);
$create_db =
"create table page_count(
script_filename text unique,
count integer
)";
$db->exec($create_db);
$db->close();
}
}
//old
function old_mf_log($log=null){
error_reporting(0);
date_default_timezone_set('Asia/Tokyo');
$file=basename(__FILE__);
$log_server[$file]=date('c');
$log_server['ip']=$_SERVER['REMOTE_ADDR'];
$log_server['uag']=$_SERVER['HTTP_USER_AGENT'];
$log_server['lg']=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
$log_server['url']=$log;
$log_str='<?php //';
foreach ($log_server as $key=>$val){
$log_str=$log_str.$key.'>'.$val.', ';
unset($val);
unset($key);
}
$log_str=$log_str.'// ?>'."\r\n";
file_put_contents('log_itunes.php', $log_str, FILE_APPEND | LOCK_EX);
}
?>
//logo
set_time_limit(120);
session_name('aixin');
session_start();
//error_reporting(E_ALL);
date_default_timezone_set('Asia/Tokyo');
//include_once('acclog.php');
$hi = new acclog();
if(count(get_included_files()) == 1){
if(array_key_exists('xx',$_GET)){
//$hi->viewlog();
$hi->viewlog2();
}else{
$name = basename(__FILE__);
echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
echo '<html><head>';
echo '<title>404 Not Found</title>';
echo '</head><body>';
echo '<h1>Not Found</h1>';
echo "<p>The requested URL /{$name} was not found on this server.</p>";
echo '</body></html>';
exit();
}
}
class acclog{
public $db_name = "acclog.db";
// select datetime(request_time,"localtime") from log;
public function acclog(){
if(!file_exists($this->db_name)){
$this->create_acclog_db();
}
if(filesize($this->db_name) > 6438912){
$this->diet();
}
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$temp = $db->prepare("insert into log ('remote_addr','http_user_agent','request_uri','http_accept_language') values (:a,:b,:c,:d)");
$temp->bindValue(':a',$_SERVER['REMOTE_ADDR'],SQLITE3_TEXT);
$temp->bindValue(':b',$this->user_agent($_SERVER['HTTP_USER_AGENT']),SQLITE3_TEXT);
$temp->bindValue(':c',$_SERVER['REQUEST_URI'],SQLITE3_TEXT);
$temp->bindValue(':d',$_SERVER['HTTP_ACCEPT_LANGUAGE'],SQLITE3_TEXT);
$temp->execute();
$db->close();
$this->page_count($_SERVER['SCRIPT_FILENAME']);
}
private function user_agent($agent){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$sql_select = sprintf("select rowid from user_agent where http_user_agent = \"%s\"",$agent);
$sql_insert = sprintf("insert into user_agent (http_user_agent) values (\"%s\")",$agent);
$temp = $db->querySingle($sql_select);
if(is_null($temp)){
$db->exec($sql_insert);
$temp = $db->querySingle($sql_select);
$db->close();
return $temp;
}else{
$db->close();
return $temp;
}
$db->close();
}
public function viewlog2(){
$db = new sqlite3($this->db_name);
$db->busyTimeout(1000);
$temp1 = $db->querySingle("select count(*) from log");
$temp2 = $db->querySingle("select count(*) from user_agent");
$temp3 = $db->querySingle("select count(*) from page_count");
$file_size = round((filesize($this->db_name)/1024/1024),2);
echo "<div>log_count:: {$temp1}</div>";
echo "<div>user_agent_count:: {$temp2}</div>";
echo "<div>page_count:: {$temp3}</div>";
echo "<div>file_size:: {$file_size} MB</div>";
echo '<br>';
$vt = $db->prepare("select * from page_count");
$vx = $vt->execute();
echo '<table border=1>';
while($vxx = $vx->fetchArray(SQLITE3_ASSOC)){
echo "<tr><td>{$vxx['script_filename']}</td><td>{$vxx['count']}</td></tr>";
}
echo '</table>';
$db->close();
}
public function viewlog(){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$temp = $db->prepare("select rowid,http_user_agent from user_agent order by http_user_agent asc");
$temp2 = $temp->execute();
while($temp3 = $temp2->fetchArray(SQLITE3_ASSOC)){
$temp4 = $this->user_agent_count($temp3['rowid']);
if($temp4 != 0){
echo "<div>{$temp3['rowid']}::{$temp3['http_user_agent']}</div>";
echo "<div>{$temp4}</div>";
echo "<div><br></div>";
}
}
$vt = $db->prepare("select * from page_count");
$vx = $vt->execute();
while($vxx = $vx->fetchArray(SQLITE3_ASSOC)){
echo "<div>[script_filename] => {$vxx['script_filename']}</div>";
echo "<div>[count] => {$vxx['count']}</div>";
}
$db->close();
}
private function user_agent_count($rowid){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$temp = $db->prepare("select count(*) as count from log where http_user_agent = :a");
$temp->bindValue(':a',$rowid);
$temp2 = $temp->execute();
while($temp3 = $temp2->fetchArray(SQLITE3_ASSOC)){
$db->close();
return $temp3['count'];
}
$db->close();
}
private function page_count($script_filename){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
//script_filename
$sql_1 = sprintf("select script_filename from page_count where script_filename = \"%s\"",$script_filename);
$sql_2 = sprintf("insert into page_count (script_filename,count) values (\"%s\",0)",$script_filename);
$sql_3 = sprintf ("update page_count set count = count + 1 where script_filename = \"%s\"",$script_filename);
$temp = $db->querySingle($sql_1);
if($temp == null){
$db->exec($sql_2);
$db->exec($sql_3);
}else{
$db->exec($sql_3);
}
$db->close();
}
private function diet(){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
//$temp = $db->prepare("delete from log where request_time < datetime('now','-2 days')");
//$temp->execute();
$sql = sprintf("delete from log where request_time < datetime('now','-1 days')");
$db->exec($sql);
$db->exec('VACUUM');
$db->close();
}
public function create_acclog_db(){
$db = new sqlite3($this->db_name);
$db->busyTimeout(10000);
$create_db =
"create table log(
request_time text default current_timestamp,
remote_addr text,
http_user_agent text,
request_uri text,
http_accept_language text
)";
$db->exec($create_db);
$create_db =
"create table user_agent(
http_user_agent text
)";
$db->exec($create_db);
$create_db =
"create table page_count(
script_filename text unique,
count integer
)";
$db->exec($create_db);
$db->close();
}
}
//old
function old_mf_log($log=null){
error_reporting(0);
date_default_timezone_set('Asia/Tokyo');
$file=basename(__FILE__);
$log_server[$file]=date('c');
$log_server['ip']=$_SERVER['REMOTE_ADDR'];
$log_server['uag']=$_SERVER['HTTP_USER_AGENT'];
$log_server['lg']=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
$log_server['url']=$log;
$log_str='<?php //';
foreach ($log_server as $key=>$val){
$log_str=$log_str.$key.'>'.$val.', ';
unset($val);
unset($key);
}
$log_str=$log_str.'// ?>'."\r\n";
file_put_contents('log_itunes.php', $log_str, FILE_APPEND | LOCK_EX);
}
?>
登録:
投稿 (Atom)