最近写了一个小程序读英语单词,Google TTS,生成一个URL,用Flash播放返回的MP3文件。
在 IE6,7,8,9 和 Chrome 浏览器下都不能成功,据查可能跟Flash的跨域加载文件有关系,但是同样的代码在FireFox 3 4和 Safari下却能正常运行。各位大侠,这可能是什么原因呢?
Google TTS 链接如: http://translate.google.com/translate_tts?tl=en&q=how%20do%20you%20do
我知道跨越的问题最简单的可以通过代理的方式解决,但是就是不明白为什么在不同的浏览器下表现的行为不一致。

解决方案 »

  1.   

    Flash Player 6 introduced a security sandbox that prevents loading data from another domains. Flash Player 7 tightened the security sandbox. try googling "flash cross-domain policy file" for further details.In last I would suggest to go with a simple php file which will act as bridge between your flash and google tts service. you will call this php from your flash by sending the url and it will return the mp3 file to your flash which can in turn play it.PHP file i mentioned above could be as simple as 
    <?php
    $url = (isset($_POST['url']) && $_POST['url']) ? $_POST['url'] : 'undefined';
     
    if ($url !='undefined') echo file_get_contents($url);
    ?>
    Hope it helps.//Ali
      

  2.   

    浏览器本来就不一致,IE里显示FLASH是<object>,火狐下是用<embed>标签,区别大!