您试图在mytableview中加载视频到目前为止在桌面视图中的视频中无法正常工作我不知道有些地方我需要的东西我没有收到视频。使用网址我想播放视频。
这是我的tableview .h文件;
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "vediopoliticalCell.h"
@interface politicalViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITableView *mytableview;
@end
这是我的tablecell.h文件代码:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface vediopoliticalCell : UITableViewCell
@property (strong,nonatomic) MPMoviePlayerController * movieplayer;
@end
这是我的tablecell.m文件代码:
@implementation vediopoliticalCell
@synthesize movieplayer;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
,这是我的tableview.m文件代码:
#import "politicalViewController.h"
#import "vediopoliticalCell.h"
@interface politicalViewController ()
@end
@implementation politicalViewController
@synthesize mytableview;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier =@"Cell";
vediopoliticalCell *cell = (vediopoliticalCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
cell= [[vediopoliticalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSURL * url = [[NSURL alloc]initWithString:@"http://localhost/image/vedios/iOS%20Tutorial-%20JSON%20Part%204%20-%20Loading%20data%20from%20an%20external%20database%20into%20an%20app.mp4"];
cell.movieplayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[cell.movieplayer.view setFrame:CGRectMake(10, 50, 100, 50)];
[self.view addSubview:cell.movieplayer.view];
return cell;
}
完成这个编码之后,我只是得到空的tableview,我无法将视频带到表格单元格中,任何人都可以告诉我我在哪里做错了什么是获取视频的正确程序
答案 0 :(得分:0)
您不使用播放或 prepareToPlay MPMoviePlayerController
的属性。添加
[cell.movieplayer play] or [cell.movieplayer prepareToPlay];
答案 1 :(得分:0)
你可以使用这段代码,它可以正常工作
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier =@"Cell";
vediopoliticalCell *cell = (vediopoliticalCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
cell= [[vediopoliticalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSURL * url = [[NSURL alloc]initWithString:@"http://localhost/image/vedios/iOS%20Tutorial-%20JSON%20Part%204%20-%20Loading%20data%20from%20an%20external%20database%20into%20an%20app.mp4"];
cell.movieplayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[cell.movieplayer.view setFrame:CGRectMake(10, 50, 100, 50)];
[cell.contentView addSubview:cell.movieplayer.view];
[cell.movieplayer.view setHidden:NO];
[cell.movieplayer.view setUserInteractionEnabled:YES];
[cell.movieplayer prepareToPlay];
[cell.movieplayer play];
return cell;
}
这将播放不在主视图上的自定义单元格上的视频
在此之前,PLZ还要交叉检查&#34; url&#34;包含文件路径&#34; http://localhost/image/vedios/iOS%20Tutorial-%20JSON%20Part%204%20-%20Loading%20data%20from%20an%20external%20database%20into%20an%20app.mp4&#34;正在返回正确的文件/路径还是也没有?