嗨試圖在mytableview中加載視頻直到現在沒有在視圖中的表視圖中工作我不知道所以一些我在哪裏我沒有得到視頻。使用我想要播放視頻的網址。在ios中使用url在桌面視圖中播放視頻
這是我的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 [email protected]"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後我不能夠把視頻中的表格單元格可以在任何告訴我在哪裏,我做錯了什麼是正確的程序來獲取視頻
爲什麼要在self.view中添加table view cell? – fibnochi
您應該在單元格的layoutSubView方法中將電影播放器視圖添加爲單元格的子視圖。 – fibnochi
在tableView:didSelect方法中調用[cell.movieplayer play]; – fibnochi