如何从类型为.3gp的URL播放视频文件

时间:2011-12-05 09:47:42

标签: iphone

提前致谢。我想实现代码以从URL以编程方式在iphone中播放视频。我写了这样的代码。

 NSURL *url = [NSURL    URLWithString:@"http://91.220.127.40/Celebrity_subCategoryItems/rc4.3gp"];//@"http://www.businessfactors.de/bfcms/images/stories/videos/defaultscreenvideos.mp4"];
MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL:     url];
[[player view] setFrame: [self.view bounds]];  // frame must match parent view
[self.view addSubview: [player view]];
[player play];

但它没有播放.3gp类型的文件。如果有人知道请帮助我。

2 个答案:

答案 0 :(得分:3)

我用iphone sdk成功播放.3gp,我的代码是:

NSString *soundLocalPath  = [[NSBundle mainBundle] pathForResource:@"Demo_video" ofType:@"3gp"];

NSURL *tempUrl   = [NSURL fileURLWithPath:soundLocalPath];

self.soundUrlPath = tempUrl;

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: self.soundUrlPath];

self.mpMoviePlayer = player;

[player release];

[self.mpMoviePlayer prepareToPlay];
[self.mpMoviePlayer.view setFrame: self.view.bounds];  // player's frame must match parent's

[self.view addSubview: self.mpMoviePlayer.view];

[self.mpMoviePlayer play];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieFinishedCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:player];


-(void) movieFinishedCallback:(NSNotification*) aNotification
{
    MPMoviePlayerController *player = [aNotification object];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:player];

    [player autorelease];
}

答案 1 :(得分:0)

我们还可以播放扩展名为.3gp的文件,但要播放我们需要一些压缩标准,将文件转换为所有移动支持的格式(3GPP - 移动平衡质量[H.263接近128 kbps,10 fps] ,128 * 96; AMR))。所以它现在正在播放。