0

我正在寻找一个播放列表格式的表格视图控制器页面,其中包含单元格中的视频。单击公开按钮时,将播放视频等。关于如何解决这个问题的任何想法?..或者一个好的教程的链接?我一直在为此绞尽脑汁.. 花了这么多时间在网上冲浪无济于事.. 任何帮助将不胜感激并投票感谢

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

这是我的头文件

 #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>
4

1 回答 1

1

添加 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];
于 2012-10-15T12:52:30.290 回答