国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

解決播放來自另一個網(wǎng)站的mp3文件的CORS錯誤
P粉662361740
P粉662361740 2024-03-31 22:04:39
0
1
662

我遇到的問題是,我的 React 應(yīng)用程序無法播放來自其他來源的音頻,并出現(xiàn) CORS 錯誤。 示例:https://audio.podigee-cdn.net/1041740-m-0fcf92e897e7cd93200a43cf103a75fb.mp3

奇怪的是,當(dāng)我訪問 https://www.w3schools.com/tags/tag_audio.asp 時,輸入上面的網(wǎng)址并單擊播放即可。

在我的本地 React 應(yīng)用程序上,我隨后獲得 302 狀態(tài)和重定向。音頻標(biāo)記包含 crossOrigin="anonymous" 和 src 元素中的 url。

在 W3Schools 上,它會以某種方式進行重定向,我只從重定向的 URL 中獲得狀態(tài) 206。

如何重現(xiàn):

  1. git 克隆 https://github.com/SamTV12345/PodFetch.git
  2. 遵循“構(gòu)建”部分中的自述文件說明
  3. git checkout 起源/開發(fā)
  4. 添加任何超過 5 集的播客。
  5. 點擊 CloudIcon

P粉662361740
P粉662361740

全部回復(fù)(1)
P粉801904089

您需要通過 new Audio(url) 而不是 XMLHttpRequest 導(dǎo)入 mp3 URL,以避免 CORS。例如:

class PlaySound extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      play: false
    };

    this.url = "https://audio.podigee-cdn.net/1041740-m-0fcf92e897e7cd93200a43cf103a75fb.mp3";
    this.audio = new Audio(this.url);
    this.togglePlay = this.togglePlay.bind(this);
  }

  togglePlay() {
    const wasPlaying = this.state.play;
    this.setState({
      play: !wasPlaying
    });

    if (wasPlaying) {
      this.audio.pause();
    } else {
      this.audio.play();
      setInterval(()=>{
        console.clear();
        let seconds = new Date().getSeconds();
        let points = '.'.repeat(seconds % 4);
        console.log(`Loading audio${points}`);
      }, 1000);
    }
  }

  render() {
    return (
      
); } } ReactDOM.render(, document.getElementById("root"));
sssccc
sssccc

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板