Ios 如何将.mp4添加到uitableviewcell中的按钮

Ios 如何将.mp4添加到uitableviewcell中的按钮,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我是XCode新手,在故事板中构建了UITableView。第一个UITableViewCell有一个按钮,按下该按钮时,应加载.mp4全屏。我正在使用MediaPlayerFramework来实现这一点 我的.mp4文件在项目中,它出现在CopyBundleResources中…但我肯定错过了一个步骤,因为我在IOS模拟器中选择按钮时出现以下错误: “*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:”*-[NSURL initFileURLWit

我是XCode新手,在故事板中构建了UITableView。第一个UITableViewCell有一个按钮,按下该按钮时,应加载.mp4全屏。我正在使用MediaPlayerFramework来实现这一点

我的.mp4文件在项目中,它出现在CopyBundleResources中…但我肯定错过了一个步骤,因为我在IOS模拟器中选择按钮时出现以下错误:

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:”*-[NSURL initFileURLWithPath:::nil字符串参数”

我还有这样一个警告:“依赖性分析警告:警告:没有规则处理架构i386的文件类型“/Users/./my_mov1.mp4”

以下是TableViewController子类中的代码:

RecipleTableViewController.h

@interface RecipleTableViewController : UITableViewController {


}

-(IBAction)playvideo;

@end
RecipleTableViewController.m

#import "RecipleTableViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface RecipleTableViewController ()

@end

@implementation RecipleTableViewController

-(IBAction)playvideo {


    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"my_mov" ofType:@"mp4"]];
    MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:playercontroller];

    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [playercontroller.moviePlayer play];
}


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

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

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
 //   return 0;
//}

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

    // Configure the cell...

    //return cell;
//}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

 */

@end
#导入“RecipleTableViewController.h”
#进口
@接口RecipleTableViewController()
@结束
@RecipleTableViewController的实现
-(IBAction)播放视频{
NSURL*url=[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@“mp4”类型的“my_mov”];
mpmovieplayervewcontroller*playercontroller=[[mpmovieplayervewcontroller alloc]initWithContentURL:url];
[自我呈现电影播放服务控制器激活:播放控制器];
playercontroller.moviePlayer.movieSourceType=mpmoviesourcetype文件;
[playercontroller.moviePlayer play];
}
-(id)initWithStyle:(UITableViewStyle)样式
{
self=[super initWithStyle:style];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//取消对下一行的注释以保留演示文稿之间的选择。
//self.clearselectiononviewwillappear=否;
//取消对以下行的注释,以在此视图控制器的导航栏中显示编辑按钮。
//self.navigationItem.rightBarButtonItem=self.editButtonItem;
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
#pragma标记-表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
#警告:方法实现可能不完整。
//返回节数。
返回1;
}
//-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
//{
#警告:方法实现不完整。
//返回节中的行数。
//返回0;
//}
//-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
//{
//静态NSString*CellIdentifier=@“Cell”;
//UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//配置单元格。。。
//返回单元;
//}
/*
//替代以支持表视图的条件编辑。
-(BOOL)tableView:(UITableView*)tableView caneditrowatinexpath:(nsindepath*)indepath
{
//如果不希望指定的项可编辑,则返回“否”。
返回YES;
}
*/
/*
//替代以支持编辑表格视图。
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径
{
如果(editingStyle==UITableViewCellEditingStyleDelete){
//从数据源中删除该行
[tableView deleteRowsAtIndexPaths:@[indexPath]和RowAnimation:UITableViewRowAnimationFade];
}   
else if(editingStyle==UITableViewCellEditingStyleInsert){
//创建相应类的新实例,将其插入数组,并向表视图添加新行
}   
}
*/
/*
//替代以支持重新排列表视图。
-(void)tableView:(UITableView*)tableView移动rowatinexpath:(nsindepath*)从indepath到indepath:(nsindepath*)到indepath
{
}
*/
/*
//重写以支持表视图的条件重新排列。
-(BOOL)tableView:(UITableView*)tableView可以移动rowatinexpath:(nsindepath*)indepath
{
//如果不希望该项目可重新订购,则返回“否”。
返回YES;
}
*/
/*
#pragma标记-导航
//在基于故事板的应用程序中,您通常需要在导航之前做一些准备
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方
{
//使用[segue destinationViewController]获取新的视图控制器。
//将选定对象传递给新的视图控制器。
}
*/
@结束
你知道我(肯定)遗漏了什么吗


谢谢!

您正在尝试获取
my_mov
的URL,而实际文件名似乎是
my_mov1

您能否确认表达式>[NSBundle mainBundle]pathForResource:@“my_mov”的结果:@“mp4”类型“]不是nil?它不应该是nil,它应该是.mp4文件…但是我没有正确地编写表达式,似乎…捕捉得很好!+给鹰眼的1个。嗨!实际上,我在应用程序中有六个电影文件,从我的电影到我的电影,都显示了依赖性警告。以上只是五个例子中的一个。很抱歉给你带来了困惑。