MPMoviePlayer只播放声音

时间:2014-02-21 15:56:50

标签: ios objective-c uitableview mpmovieplayer

尝试将我的视频放在UITableViewCell中的自定义视图中。

videoView是一个UIView:

以下是选择单元格时:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    FeedCustomCell *cell = [[FeedCustomCell alloc] init];

    NSURL *url = [NSURL URLWithString:_videoPathString];

    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.controlStyle = MPMovieControlStyleNone;

    CGRect previewFrame = CGRectMake(cell.videoView.frame.origin.x,
                                     cell.videoView.frame.origin.y,
                                     cell.videoView.frame.size.width,
                                     cell.videoView.frame.size.height);

    moviePlayer.view.frame = previewFrame;
    moviePlayer.repeatMode = MPMovieRepeatModeOne;

    [self.view addSubview:moviePlayer.view];
    [self.view bringSubviewToFront:moviePlayer.view];

    [moviePlayer play];
}

这是我的手机:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"FeedCustomCell";
    FeedCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    cell.username.text = [NSString stringWithFormat:@"%@", _usernameString];
    cell.createdDate.text = [NSString stringWithFormat:@"%@", _createdString];

    return cell;
}

我只在选择单元格时向cell.videoView添加内容。我做错了吗?

视频正在播放声音,但没有视觉效果。

1 个答案:

答案 0 :(得分:0)

而不是:

[self.view addSubview:moviePlayer.view];

试试这个:

[self.view.contentView addSubview:moviePlayer.view];
相关问题