3
votes

I use this code in my app to embed youtube video

NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: transparent;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];

The youtube video url is from urlString, like "http://www.youtube.com/v/QfWGRIlpNBE". And this code works fine.

My question is, if the video is in flash format, then it can not be played on iphone, and I got a slosh cross the play button.

How can I detect if youtube video is a flash format or H.264 format? I only have the url of the video.

1
anyone can help me? Thanks, really appreciateGargamal

1 Answers

1
votes

If you need to know before you construct your HTML, I think the only way would be to use the YouTube API. You could query for the video in your question with the following:

http://gdata.youtube.com/feeds/api/videos?q=QfWGRIlpNBE&max-results=1&v=2&format=1

There are no results for that video ID in H.263.

See http://code.google.com/apis/youtube/2.0/reference.html#formatsp for API doc.

Otherwise, you could just use an <iframe>: http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html