1

我正在使用此处找到的此代码提供一个 mp3 文件。

我的 mp3 立即开始播放,当前时间等。但我没有持续时间

如果直接链接到文件,我会得到它。

这是我的IOS代码:

-(void)initAVPlayer{
    NSString *link = @"<link go php file>";
    NSURL *url = [NSURL URLWithString:link];
    AVURLAsset *asset = [AVURLAsset assetWithURL: url];
    Float64 duration = CMTimeGetSeconds(asset.duration); // nothing here
    AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:asset];
    avPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
    CMTime interval = CMTimeMake(20, 1000);
     __unsafe_unretained typeof(self) weakSelf = self;
    playbackObserver = [avPlayer addPeriodicTimeObserverForInterval:interval queue:dispatch_get_current_queue() usingBlock:^(CMTime time) {
    [weakSelf updatePlayerValues];
}];
    playButton.enabled = NO;
    [avPlayer play];
}
-(void)updatePlayerValues{
    CMTime duration = [[[[[avPlayer.currentItem tracks] objectAtIndex:0] assetTrack]asset]duration]; // nothing here
    CMTime endTime = CMTimeConvertScale (duration, avPlayer.currentTime.timescale, kCMTimeRoundingMethod_RoundHalfAwayFromZero);
    if (CMTimeCompare(endTime, kCMTimeZero) != 0) {
        // do some stuff.
    }
}

我猜这与我的php代码有关。

提前致谢。

编辑:这是 HTTP 标头:

Array(
   [0] => HTTP/1.1 200 OK
   [1] => Date: Fri, 04 Oct 2013 19:30:26 GMT
   [2] => Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8y DAV/2 PHP/5.3.6
   [3] => X-Powered-By: PHP/5.3.6
   [4] => Content-Disposition: inline; filename="Radio head beat.mp3"
   [5] => Pragma: no-cache
   [6] => Content-Length: 1846251
   [7] => Connection: close
   [8] => Content-Type: audio/mpeg
)
4

0 回答 0