douhan0562 2013-08-29 18:35
浏览 46
已采纳

禁用YouTube或可能修复桌面以外的设备

I have a website i have been working on where we have an iframe that pulls in the newest video from given YouTube channels. It works just fine on the desktop or device that can run flash but when a user is on an IOS device or some android devices nothing shows up there. Its an empty square. Is there a good fix that someone knows or a way I can get around this? I have tried detecting if it is a mobile platform and to display a filler image instead but still doesn't work on all devices. Any suggestions would be great.

I did also consider just taking the YouTube API and getting the image of the video and showing that then the user clicks it it just brings you to the video, which would be a fix but a last resort fix.

Also in-case anyone has a better way for the code to work then what I have below id love to see it!

<div class="span6 data_video">
    <?php
        $url = 'http://gdata.youtube.com/feeds/api/users/'. $Youtube .'/uploads?max-results=1';
        $xml = simplexml_load_file($url);
        foreach ($xml->entry as $entry) :

            // get nodes using mrss ('media' rss namespace)
            $kids = $entry->children('http://search.yahoo.com/mrss/');

            // for the embed src (just the flv location - you'll need to print out the rest of the object/embed tag
            $attributes = $kids->group->content[0]->attributes();
            $flv = $attributes['url'];

        endforeach; 
    ?>
    <iframe align="left" width="100%" height="315" src="<?php echo $flv; ?>" frameborder="0" allowfullscreen></iframe>
</div>

The code to detect a mobile browser im using is just http://detectmobilebrowsers.com/

  • 写回答

1条回答 默认 最新

  • dtwy2858 2013-08-29 20:35
    关注

    Taken from Drewid in on another stackoverflow post...

    var hasFlash = false;
    try {
      var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
      if(fo) hasFlash = true;
    }catch(e){
      if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true;
    }
    

    You can also stream youtube via html 5 by adding the url var ?html5=1 to the iframe address

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?