Use YouTube video must init a youtube player
There have 2 player we can use
- flash player
- iframe player
I suggest use iframe player because it can support flash and HTML5
If use Apple mobile devices, they can't support flash
Use iframe player can solve this problem
This is a note to iframe API
1.First check load iframe API
2.Init YouTube player
playerVars can refer YouTube 嵌入式播放器参数
3.Handle onPlayerReady, onPlayerStateChange, error
onError error code
- 2 – The request contains an invalid parameter value. For example, this error occurs if you specify a video ID that does not have 11 characters, or if the video ID contains invalid characters, such as exclamation points or asterisks.
- 5 – The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred.
- 100 – The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private.
- 101 – The owner of the requested video does not allow it to be played in embedded players.
- 150 – This error is the same as 101. It's just a 101 error in disguise!
Youtube Data api
Get video data api
It return format is XML
It return format is json
Player API 其中有個參數允許強制使用 HTML5 player 這建議有個好處與壞處
壞處是如果遇到訊源只有 flash 格式的影片 player 會重啟為 flash player
用 gData 抓影片資訊可抓到其中一個
content 的 key 其中就有提供此影片所帶有的格式
- 5 - HTTP URL to the embeddable player (SWF) for this video. This format is not available for a video that is not embeddable. Developers commonly add &format=5 to their queries to restrict results to videos that can be embedded on their sites.
- 1 - RTSP streaming URL for mobile video playback. H.263 video (up to 176x144) and AMR audio.
- 6 - RTSP streaming URL for mobile video playback. MPEG-4 SP video (up to 176x144) and AAC audio.