Author Topic: Chương trình xem truyền hình trực tuyến  (Read 17012 times)

cmxq

  • Administrator
  • PHP Intermediate
  • *****
  • Posts: 1339
    • View Profile
    • Email
Chương trình xem truyền hình trực tuyến
« on: September 23, 2007, 12:20:38 AM »
1. Lý thuyết:

Các chương trình TV thường được phát đi từ một máy chủ nào đó dưới dạng một file stream gần giống như file nhạc hay video. Điều đó có nghĩa là ta có thể "bắt" các kênh này với 2 điều kiện:
- 1: Kênh TV đó phải có một cái URI
- 2: Tồn tại một plug in hoặc một cái object hỗ trợ việc xem dữ liệu dưới dạng kênh audio/video.

Cả 2 thứ này tồn tại đầy rẫy trên Internet.

II. Đoạn mã đơn giản để bắt kênh TV:
Ở đây tôi "chôm" một function viết bằng javascript. Hàm này có đầu vào là địa chỉ URI của cái kênh TV và dòng mô tả. Nhiệm vụ chính của hàm này là tải một cái object media player của M$oft, tiếp đó gán cái địa chỉ URI của kênh TV vào cái tham số source của object trên rồi ghi vào nội dung của 2 thẻ div cái đối tượng trên và dòng chú thích:

Code: [Select]
<script language="javascript">
function LoadVideo(strSource,strDesc)
{
    var s;
    s="<OBJECT id=winMediaPlayerID ";
            s+="codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715";
            s+="type=application/x-oleobject width=352 height=355 ";
            s+="standby=\"Loading Microsoft Windows Media Player components...\" ";
            s+="width=388 classid=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6 ";
            s+="name=winMediaPlayer>";
        s+="<PARAM NAME=\"URL\" VALUE=\""+strSource+"\"> ";
        s+="<PARAM NAME=\"rate\" VALUE=\"1\">";
        s+="<PARAM NAME=\"balance\" VALUE=\"0\">";
        s+="<PARAM NAME=\"currentPosition\" VALUE=\"0\">";
        s+="<PARAM NAME=\"defaultFrame\" VALUE=\"0\">";
        s+="<PARAM NAME=\"playCount\" VALUE=\"999\">";
        s+="<PARAM NAME=\"CursorType\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"autoStart\" VALUE=\"1\">";
        s+="<PARAM NAME=\"currentMarker\" VALUE=\"0\">";
        s+="<PARAM NAME=\"invokeURLs\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"volume\" VALUE=\"50\">";
        s+="<PARAM NAME=\"mute\" VALUE=\"0\">";
        s+="<PARAM NAME=\"stretchToFit\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"windowlessVideo\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enabled\" VALUE=\"1\">";
        s+="<PARAM NAME=\"fullScreen\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enableContextMenu\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enableErrorDialogs\" VALUE=\"0\">";       
        s+="<Embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/windowsmedia/download/' src='"+strSource+"' src='"+strSource+"' Name='MediaPlayerTV' ";
            s+="width='352' height='355' ";           
            s+="AutoSize='1' ";
            s+="AutoStart='1' ";
            s+="ClickToPlay='1' ";
            s+="DisplaySize='1' ";
            s+="EnableContextMenu='0' ";
            s+="EnableFullScreenControls='1' ";
            s+="EnableTracker='1' ";
            s+="Mute='0' ";
            s+="PlayCount='999' ";
            s+="ShowControls='1' ";
            s+="ShowAudioControls='1' ";
            s+="ShowDisplay='0' ";
            s+="ShowGotoBar='0' ";
            s+="ShowPositionControls='1' ";
            s+="ShowStatusBar='1' ";
            s+="ShowTracker='1'> ";
            s+="</embed> ";
    s+="</OBJECT>";
    document.getElementById("MediaPlayer").innerHTML=s;
    document.getElementById("MediaDesc").innerHTML="<B>" + strDesc + "</B>";
}
</script>

Kết quả cuối cùng là gọi hàm jscript trên ở vị trí muốn hiển thị. VD:

<p onclick='LoadVideo("mms://www.vtc.com.vn:556/VTC5_2105","Truyền hình cáp VTC 5");'>VTC 5</p>

III. Nâng cao.
Vấn đề là chúng ta có quá nhiều kênh TV như vậy trên Internet, vì vậy có lẽ chúng ta nên tổ chức thành một cái CSDL chứa các thông tin về kênh TV, mô tả và phân loại chúng. Cái này thì phải viết = PHP và ... dành cho các bạn ;D
« Last Edit: May 24, 2008, 12:55:08 AM by +^^+SorivevoL+^^+ »
Hãy bấm LIKE nếu bạn thích bài viết này

thesimvn

  • PHP Intermediate
  • *
  • Posts: 174
    • View Profile
    • Max men health
Re: Chương trình xem truyền hình trực tuyến
« Reply #1 on: June 01, 2008, 08:42:31 AM »
cho em hỏi :<p onclick='LoadVideo("mms://www.vtc.com.vn:556/VTC5_2105","Truyền hình cáp VTC 5");'>VTC 5</p> là đặt ở đâu, sau em làm nó chỉ hiện ra chữ VTV 5 thôi hà

KenyLieou

  • Global Moderator
  • PHP Intermediate
  • *****
  • Posts: 908
  • Nothing's Impossible
    • MSN Messenger - kiensuy2000@hotmail.com
    • View Profile
    • Email
Re: Chương trình xem truyền hình trực tuyến
« Reply #2 on: June 01, 2008, 05:27:18 PM »
đặt ở chổ nào bạn muốn nó load
+ PHPVN Supporter or Spamer :D 
+ Email: kenylieou@gmail.com. Please feel free to contact me

thesimvn

  • PHP Intermediate
  • *
  • Posts: 174
    • View Profile
    • Max men health
Re: Chương trình xem truyền hình trực tuyến
« Reply #3 on: June 02, 2008, 07:29:33 PM »
Sao em làm thế nầy nó chỉ hiện chữ VTC không vậy  :-\
Quote
<script language="javascript">
function LoadVideo(strSource,strDesc)
{
    var s;
    s="<OBJECT id=winMediaPlayerID ";
            s+="codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715";
            s+="type=application/x-oleobject width=352 height=355 ";
            s+="standby=\"Loading Microsoft Windows Media Player components...\" ";
            s+="width=388 classid=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6 ";
            s+="name=winMediaPlayer>";
        s+="<PARAM NAME=\"URL\" VALUE=\""+strSource+"\"> ";
        s+="<PARAM NAME=\"rate\" VALUE=\"1\">";
        s+="<PARAM NAME=\"balance\" VALUE=\"0\">";
        s+="<PARAM NAME=\"currentPosition\" VALUE=\"0\">";
        s+="<PARAM NAME=\"defaultFrame\" VALUE=\"0\">";
        s+="<PARAM NAME=\"playCount\" VALUE=\"999\">";
        s+="<PARAM NAME=\"CursorType\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"autoStart\" VALUE=\"1\">";
        s+="<PARAM NAME=\"currentMarker\" VALUE=\"0\">";
        s+="<PARAM NAME=\"invokeURLs\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"volume\" VALUE=\"50\">";
        s+="<PARAM NAME=\"mute\" VALUE=\"0\">";
        s+="<PARAM NAME=\"stretchToFit\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"windowlessVideo\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enabled\" VALUE=\"1\">";
        s+="<PARAM NAME=\"fullScreen\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enableContextMenu\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enableErrorDialogs\" VALUE=\"0\">";       
        s+="<Embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/windowsmedia/download/' src='"+strSource+"' src='"+strSource+"' Name='MediaPlayerTV' ";
            s+="width='352' height='355' ";           
            s+="AutoSize='1' ";
            s+="AutoStart='1' ";
            s+="ClickToPlay='1' ";
            s+="DisplaySize='1' ";
            s+="EnableContextMenu='0' ";
            s+="EnableFullScreenControls='1' ";
            s+="EnableTracker='1' ";
            s+="Mute='0' ";
            s+="PlayCount='999' ";
            s+="ShowControls='1' ";
            s+="ShowAudioControls='1' ";
            s+="ShowDisplay='0' ";
            s+="ShowGotoBar='0' ";
            s+="ShowPositionControls='1' ";
            s+="ShowStatusBar='1' ";
            s+="ShowTracker='1'> ";
            s+="</embed> ";
    s+="</OBJECT>";   
    document.getElementById("MediaPlayer").innerHTML=s;
    document.getElementById("MediaDesc").innerHTML="<B>" + strDesc + "</B>";
}
</script>
<p onclick='LoadVideo("mms://www.vtc.com.vn:556/VTC5_2105","Truyền hình cáp VTC 5");'>VTC 5</p>

™[SorivevoL]™

  • Global Moderator
  • PHP Intermediate
  • *****
  • Posts: 400
    • View Profile
    • Email
Re: Chương trình xem truyền hình trực tuyến
« Reply #4 on: June 02, 2008, 07:42:40 PM »
<p onclick=..> có nghĩa là click vào thì mới chạy

cái thứ 2
document.getElementById("MediaPlayer").innerHTML=s;
phải có 1 cái <p id="MediaPlayer"></p> thì nó mới hiện ra

cuncon

  • PHP Starter
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Chương trình xem truyền hình trực tuyến
« Reply #5 on: November 15, 2008, 11:15:39 PM »
cac bac oi xem em post lai code bai tren ma ko dc nhi

virutmath

  • PHP Starter
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Chương trình xem truyền hình trực tuyến
« Reply #6 on: May 25, 2010, 06:36:46 PM »
Sao đang viết dở mà lại dừng cái topic này lại thế. hic. mình vào đọc và làm theo hướng dẫn mà cũng chỉ ra đc chữ VTC5. Ko biết phải làm thế nào nó mới chạy

KENICHI

  • PHP Starter
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Chương trình xem truyền hình trực tuyến
« Reply #7 on: June 09, 2010, 12:03:53 PM »
Đoạn code javascript trên dùng sinh ra 1 object để load file stream từ nguồn về. Còn chữ "VTC5" : khi bạn click chuột vào đó sẽ tạo ra đối tượng media để xem phim. Còn việc xem được hay không tùy vào url mình truyền vào còn sống hay không !