0

我一直在使用 MPMoviePlayerController 播放 mp4 文件。视频播放正常,但根本没有音频。我已经先下载了一个功能并使用另一个功能播放。请检查下面的代码。我在这里做错什么了吗...

- (void) download_file : (NSString *) msg_url
{
    if (msg_url != nil) {

        // Download and play
        NSURL  *url = [NSURL URLWithString:msg_url];
        NSData *urlData = [NSData dataWithContentsOfURL:url];
        if ( urlData )
        {
            char file_path[512] = {0};
            get_app_data_path(OFI_VC_MAILBOX_PATH, file_path); // Give document path.

            NSString  *filePath = [NSString stringWithFormat:@"%s/%@", file_path,@"mailbox.mp4"];
            [urlData writeToFile:filePath atomically:YES];

            [self performSelectorOnMainThread:@selector(play_mp4_file:) withObject:filePath waitUntilDone:NO];
        }
    }
}

- (void) play_mp4_file : (NSString *) filepath
{
    if (is_same_view == true) {
        [self.view setUserInteractionEnabled:YES];
        if (filepath != nil) {

            NSURL *file_url = [NSURL fileURLWithPath:filepath];
            moviePlayer =  [[MPMoviePlayerController alloc]
                            initWithContentURL:file_url];

            moviePlayer.controlStyle = MPMovieControlStyleDefault;
            moviePlayer.shouldAutoplay = YES;
            moviePlayer.useApplicationAudioSession = YES;
            [self.view addSubview:moviePlayer.view];
            [moviePlayer setFullscreen:YES animated:YES];
        }
    }
}

感谢您的帮助

4

1 回答 1

0

我已经解决了这个问题。问题在于 .mp4 扩展名,我使用了 .mov。它现在正在播放音频。

于 2012-10-29T11:26:15.063 回答