【问题标题】:Playing Video URL from Table View Selection从表视图选择中播放视频 URL
【发布时间】:2012-11-01 18:54:16
【问题描述】:

当在表格视图中选择特定项目时,我想使用 MediaPlayer 框架在 xcode 中播放视频。我已将我的代码放在下面,但不确定从这里开始。具体来说,我不确定如何将列表视图项与 url 相关联。

//  ViewController.m
//  Test
//


#import "ViewController.h"

@implementation ViewController
@synthesize tableData;


- (void)viewDidLoad
{

    tableData = [[NSArray alloc] initWithObjects:@"Bacon", @"Banana", @"Big", @"Billious", nil];

    [super viewDidLoad];
}

#pragma mark - TableView Data Source Methods

- (NSInteger)tableView:(UITableView *)tableView
    numberOfRowsInSection:(NSInteger)section
{
    return [tableData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    UITableViewCell *cell = nil;

    cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
    }

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];

    return cell;

}

#pragma mark - TableView Delegate Methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSString *moviePath = @"http://specified URL";
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
    [theMovie play];
    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];


}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

【问题讨论】:

    标签: ios objective-c uitableview video mpmovieplayercontroller


    【解决方案1】:

    objectAtIndex:indexPath.row 不包含 urlString,因为您的数组 tabledata 没有任何 url。尝试获取特定元素的url,然后在moviePath中使用它。

    NSURL *url= [NSURL URLWithString:@"http://www.xyz.com/video/x109z02"];
    theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    theMoviPlayer.scalingMode = MPMovieScalingModeFill;
    theMoviPlayer.view.frame = CGRectMake(0, 60, 320, 350);
    [self.view addSubview:theMoviPlayer.view];
    [self.theMoviPlayer play];
    

    还添加框架,然后将其导入头文件。

    【讨论】:

      猜你喜欢
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 2015-03-09
      • 2019-02-22
      相关资源
      最近更新 更多