
พอดีเอา Flash video player จากเว็บ http://www.jeroenwijering.com (jw_flv_player) มาใช้งานในการเล่นไฟล์วิดีโอ .flv บนเว็บ
โดยโค้ด jw_flv_player นี้มีฟังก์ชั่นช่วยในการเก็บสถิติคนคลิกดูวิดีโอได้ด้วย เพียงแค่เพิ่มคำสั่ง callback เข้าไป ดังนี้
<div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var s1 = new SWFObject("mediaplayer.swf","mediaplayer","300","170","7");
s1.addParam("allowfullscreen","true");
s1.addVariable("width","300");
s1.addVariable("height","170");
s1.addVariable("file","video.flv");
s1.addVariable("image","video.jpg");
s1.addVariable("title","Video Title");
s1.addVariable("id","1");
s1.addVariable("callback", "http://www.yourweb.com/statistics.php");
s1.write("container");
</script>
ตรง callback ให้กำหนดไฟล์ที่รับข้อมูลที่ถูกส่งไป โดยค่าที่ส่งไป ได้แก่
1. file (full url if available)
2. title
3. id
4. state 1=start, 3=end
5. duration if state=3 (end)
โดยในไฟล์ที่รับข้อมูล ในเว็บ
jeroenwijering.com มีตัวอย่างการเก็บข้อมูลแบบง่ายๆ เอาไว้ดังนี้ ไฟล์ statistics.php
<?php
/*
* This is a small script you can use for tracking statistics in the flash players.
* You have to set the location of this script as the "callback" flashvar for your player first.
* Second, you'll have to create an empty textfile "statistics.log" that is writeable in the same directory as this script.
* Now, the script will add a line with the title each flash player item that is either started or completely listened.
* You can also save the item's file url (it's variable is $file), or, if provided in the playlist, a unique id ($id)
*/
extract($_POST, EXTR_PREFIX_SAME, "post_");
$file = $_POST["file"];
$title = $_POST["title"];
$id = $_POST["id"];
$state = $_POST["state"];
$filename = "statistics.log";
// check to see if $filename exists, if not, create it.
if (!file_exists($filename))
{
$fh = fopen($filename, 'w');
fclose($fh);
}
$somecontent = $title . ": " . $file . ": " . $state . "\n";
// open $filename for append.
// the file pointer is at the bottom of the file hence
// $somecontent will be appended to the file.
$handle = fopen($filename, 'a') or die("Could not open file: " . $filename . "\n");
// Write $somecontent to the open file.
fwrite($handle, $somecontent) or die("Could not write to file: " . $filename . "\n");
// echo "Success, wrote: " . rtrim($somecontent) . " to file: " . $filename . "\n";
fclose($handle);
?>
(
ตัวสีเขียว ได้รับคำแนะนำจาก
ออย(
ดูโอคอร์) ว่าให้ลองใส่ดู หาก extract บรรทัดก่อนหน้าไม่ทำงาน)
วิธีการนี้ก็คือ เก็บข้อมูลสถิติเข้าไปไว้ในไฟล์ statistics.log
หรือถ้าเราต้องการเอาข้อมูลไปเก็บเข้าไว้ในฐานข้อมูลก็สามารถเอาคำสั่ง PHP ต่อกับ MySQL เพื่อเก็บข้อมูลได้เลย (ข้ามวิธีการเก็บเข้าไฟล์แบบตัวอย่างข้างต้น)
และถ้าต้องการเก็บวันที่,เวลา และ IP ก็เพิ่มคำสั่งต่อไปนี้ลงไปได้
$ip = $_SERVER['REMOTE_ADDR'];
$viewdate = date("Y-m-d H:i:s");
ข้อมูลเพิ่มเติม
*
http://www.jeroenwijering.com/?item=JW_FLV_Media_Player *
http://www.jeroenwijering.com/?thread=8589 *
http://www.jeroenwijering.com/?thread=8958 *
http://www.jeroenwijering.com/?thread=8492
Permanent Link: Poakpong's Blog [www.poakpong.com/1106]
Recent posts in "Mac Stuff"
เพิ่งอัพเดตปลั๊กอินเวิร์ดเพรสไปเมื่อวันก่อน (ของ yaosan) ปรากฎว่าเวอร์ชั่นใหม่ มันไม่สามารถทำให้ทำให้ไม่ีปุ่มเพลย์ แต่มีแถบบาร์แบบที่หายไปเวลา้เอาเมาส์ออก คือถ้าจะเอาแถบแบบหายไปได้ ต้องมีปุ่มเพลย์ด้วย ... เลยได้กลับไปใช้เวอร์ชั่นเก่าเหมือนเดิม
