2012-10-15 104 views
0

我正在创建一个播放列表格式的tableview控制器页面,该页面包含单元格中的视频。点击披露按钮后,视频播放等。关于如何去做这件事的任何想法?..或者一个关于它的好教程的链接? 我已经在this..spending那么多时间在网上冲浪无果开裂我的头.. 任何帮助将非常感激并表决 感谢带有视频显示的表格

这里是我的样品code..i知道它可能不是去了解它的最佳方式,因此它是不行的工作

这里是我的头文件

#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

您想在播放按钮后播放单元格内或其他控制器中的视频吗? – Deepak

+0

我想要点击披露按钮后播放视频,就像youtube的工作方式@Deepak – DanKiiing

+0

哦!所以你可以去MPMoviePlayerController。 – Deepak

回答

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]; 
+0

非常感谢这一点,但有一点!..我用什么方法将其放入,以及我需要从我的代码中删除哪些方法以用@Deepak – DanKiiing

+0

mmmm替换该方法!你可以在didSelectRowAtIndex中写入,但要记住优化代码。 我的意思是要记住内存优化。 – Deepak

+0

@ Deepak..hey man我错误,但没有出现在应用程序,甚至没有披露按钮..请帮助 – DanKiiing