iOS Mediaplayer和URL重定向

时间:2012-01-30 10:19:07

标签: objective-c ios media-player nsurlconnection redirect

我正在尝试实施MPMedia播放器来播放互联网文件。到目前为止,我已设法打开媒体播放器,其中包含我主持的视频链接。当我尝试加载不直接映射到文件但被重定向到文件的URL时,问题就开始了。

初始网址如下所示:h * tp://www.example.com/ 数字/数字/数字

当我将它放入浏览器时会自动更改为:h * tp://www.example.com/ numbers .mp4?to = numbers < / em>的

当我直接使用初始网址时,就像我使用直接网址一样,播放器出现并且在没有播放视频的情况下无法播放。

我已经尝试过NSURLConnection来获取重定向网址,但是我还没能让它工作,不知何故方法 - 连接:willSendRequest:redirectResponse:没有被调用。我想这可能是因为它已经在iOS 5中删除了,但我不知道任何替代方案,而且这种问题实际上没有记录。

这是我的代码:(我已经跳过了shortUrl初始化,它可以工作)。

NSLog(@"%@",shortUrl);

redirecionando=TRUE;

NSURLConnection * conection = [[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:shortUrl] delegate:self];
[conection start];

while(self.redirecting);

self.moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:finalurl];
moviePlayerController.view.frame = self.view.bounds;
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayerController.moviePlayer.shouldAutoplay = YES;
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.moviePlayer.fullscreen=YES;



}

- (NSURLRequest *)connection: (NSURLConnection *)inConnection
             willSendRequest: (NSURLRequest *)inRequest
            redirectResponse: (NSURLResponse *)inRedirectResponse;
{
    finalurl=inRequest.URL; 
    self.redirecting=FALSE;
    return inRequest;
}

我知道最后一个方法没有被调用,我NSLog了它。现在,当上面的代码被执行时,它只是因为while循环而等待。

顺便说一下,我不能使用外部api来发现像http://longurl.org/这样的重定向,因为该链接会返回对要求的设备的令牌访问权限 它

提前致谢。

0 个答案:

没有答案