带有视频显示的表格单元

时间:2012-10-15 12:18:41

标签: ios xcode ios5 video ios6

我希望创建一个播放列表格式的tableview控制器页面,其中包含单元格中的视频。单击公开按钮时,播放视频等。关于如何解决这个问题的任何想法?或者是一个关于它的好教程的链接? 我一直在讨论这个问题。花费大量时间浏览网页无济于事。 任何帮助将非常感谢和投票 感谢

这是我的示例代码..我知道它可能不是最好的方法,因此它不工作

这是我的头文件

 #import <UIKit/UIKit.h>
 #import <MediaPlayer/MediaPlayer.h>

 @interface BIDVideosViewController : UIViewController

 <UITableViewDelegate, UITableViewDataSource>

 @property (nonatomic,strong) NSArray *tableList;

 @end

这是我的.m文件

 #import "BIDVideosViewController.h"

 @interface BIDVideosViewController ()
 {
 MPMoviePlayerController *moviePlayer;

 }

  @end

  @implementation BIDVideosViewController

  @synthesize tableList;

  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
 }

 - (void)viewDidLoad
{
[super viewDidLoad];
UITableView *table = [[UITableView alloc]initWithFrame:self.view.bounds];
[table setDelegate:self];
[table setDataSource:self];
[self.view addSubview:table];
tableList = [[NSMutableArray alloc] initWithObjects:@"Gangan",@"SwimGood", nil];
self.tableList = array;
// Do any additional setup after loading the view.
}

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

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

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
static NSString *DisclosureButtonIdentifier = @"DisclosurebutotonIdentifier";
UITableViewCell *cell = [tableView   dequeueReusableCellWithIdentifier:DisclosureButtonIdentifier];
if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DisclosureButtonIdentifier];
}
NSInteger row = [indexPath row];
NSString *rowString = [tableList objectAtIndex:row];
cell.textLabel.text = rowString;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"Gangan" ofType:@"mp4"];
  NSURL *url = [NSURL fileURLWithPath:stringPath];
  moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
   [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                                   name:MPMoviePlayerScalingModeDidChangeNotification
                                           object:moviePlayer];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(endPlay:)
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(stopBusyIndicator:)
                                             name:MPMoviePlayerLoadStateDidChangeNotification
                                           object:moviePlayer];

moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

moviePlayer.movieControlMode = MPMovieControlModeDefault; //'movieControlMode' is deprecated

//moviePlayer.backgroundColor = [UIColor blackColor];

moviePlayer.view.frame = CGRectMake(212, 84, 600, 600);

 [self.view addSubview:moviePlayer.view];       
 [moviePlayer play];                           </i>

1 个答案:

答案 0 :(得分:2)

添加MediaPLayer框架。

MPMoviePlayerController *moviePlayer;   
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
                [[NSNotificationCenter defaultCenter] addObserver:self
                                                         selector:@selector(moviePlayBackDidFinish:) 
                                                             name:MPMoviePlayerScalingModeDidChangeNotification 
                                                           object:moviePlayer];

                [[NSNotificationCenter defaultCenter] addObserver:self
                                                         selector:@selector(endPlay:) 
                                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                                           object:moviePlayer];
                [[NSNotificationCenter defaultCenter] addObserver:self
                                                         selector:@selector(stopBusyIndicator:) 
                                                             name:MPMoviePlayerLoadStateDidChangeNotification 
                                                           object:moviePlayer];

                moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
                moviePlayer.movieControlMode = MPMovieControlModeDefault;
                //moviePlayer.backgroundColor = [UIColor blackColor];

                    moviePlayer.view.frame = CGRectMake(212, 84, 600, 600);

                }
                [self.view addSubview:moviePlayer.view];
                [moviePlayer play];