代码之家  ›  专栏  ›  技术社区  ›  Chilly Zhong

如何在iPhone上的网站上播放音频文件?

  •  2
  • Chilly Zhong  · 技术社区  · 16 年前

    NSURL *bgURL = [NSURL URLWithString:@"http://www.radioslots.com/iphone/test/tmp/1.mp3"];
    bgPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:bgURL error:nil];
    bgPlayer.numberOfLoops = -1;
    if (bgPlayer) {
        [bgPlayer play];
    }
    
    3 回复  |  直到 16 年前
        1
  •  1
  •   ACBurk    16 年前

    AVAudioPlayer不是用来打开网络流的,我可能弄错了,但我很确定这是不可能的。

    在我脑海中,我能想到两种可能有效的方法: 1.使用MPMoviePlayer,因为它可以打开网络流,尽管名称与音频一起工作。唯一的问题是这会弹出带有控件的模式播放器。 2.下载网络文件并在本地存储,然后使用AVAudioPlayer播放本地文件。

        2
  •  1
  •   Community Mohan Dere    9 年前

    here 。请检查并用您的url替换此处使用的url。。

       NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"songname" ofType:@"mp3"];
     NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
    

    具有

    NSString *soundFilePath = @"Your URL";
    NSURL *newURL = [[NSURL alloc] initWithString: soundFilePath];
    
        3
  •  0
  •   Madhup Singh Yadav    16 年前

    有适当的文件可在 this link

    NSError *error;
    bgPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:bgURL error:&error];
    

    希望这有帮助。