MPmovieplayer播放问题获取_itemFailedToPlayToEnd:在ios中

时间:2014-01-23 09:29:19

标签: ios json video-streaming nsurlconnection

嗨,我正在尝试查看来自我的服务器的视频,因为我已将视频网址存储在mysql数据库中 使用json和php代码我将url传递给iOS但现在我遇到了一些问题

这是我用来获取要在表格单元格中查看的视频网址的代码

表格单元.m文件代码:

  #import "vediopoliticalCell.h"
  #import "vedios.h"
  @implementation vediopoliticalCell
 //@synthesize movieplayer,titile;

- (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
}

-(void)setDataSource:(vedios *)inVideosObj
{
self.titile.text = inVideosObj.title;

NSURL *url =[NSURL URLWithString:inVideosObj.video];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
connection =[[NSURLConnection alloc] initWithRequest:request delegate:self];
self.responseData = [[NSMutableData alloc]init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
 {
      [self.responseData appendData:data];
 }

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
 {
    NSString *url =[NSString stringWithUTF8String:[self.responseData bytes]];
    MPMoviePlayerController *mov = [[MPMoviePlayerController    alloc]initWithContentURL:   [NSURL URLWithString:url]];
  [self.movieplayer.view setFrame:CGRectMake(10,20, 100, 100)];
 NSLog(@"vedio %@",mov);
  self.movieplayer = mov;
   //[self.view addSubview:self.movieplayer.view];
     [self.movieplayer prepareToPlay];
     [self.movieplayer play];
 }
   @end

编码后我无法在我的表格单元格中播放视频

即时问题:

      2014-01-23 14:36:46.272 video[2123:a0b] vedio <MPMoviePlayerController: 0xa67c440>
      2014-01-23 14:36:46.339 video[2123:a0b] _itemFailedToPlayToEnd: {
         kind = 1;
         new = 2;
        old = 0;
     }

在我的控制台中这样,所以请帮我解决这个问题

提前感谢...

1 个答案:

答案 0 :(得分:1)

URL损坏时会出现此错误。你说你在你的服务上使用JSON,据我理解这一行

NSString *url =[NSString stringWithUTF8String:[self.responseData bytes]];

您收到JSON而不是网址。首先,检查您收到的内容,如果它真的是JSON使用下一个示例:

NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:self.responseData options:kNilOptions error:&error];
[self.responseData setData:0]; // don't forget to clean your response data
if (!error) {
    NSString *urlString = json[@"KEY_THAT_YOU_USE_FOR_VIDEO_URL"];
    NSURL *videoURL = [NSURL URLWithString:urlString];
}