在ios中使用json传递视频网址

时间:2014-01-23 07:38:03

标签: ios json video nsurlconnection

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

之前使用相同的格式从我的服务器获取图像,但现在我想查看视频,这是我第一次处理视频无法获取它

这是我用来获取url表单数据库并喜欢ios nsurl格式的代码

tabecell.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;
             {
                 MPMoviePlayerController *play = [[MPMoviePlayerController    alloc]initWithContentURL:self.responseData];
             }

在此代码中:

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection;
             {
                 MPMoviePlayerController *play = [[MPMoviePlayerController    alloc]initWithContentURL:self.responseData];
             }

我得到了一个警告: 不兼容的指针类型将'NSMutableData '发送到Nsurl类型的参数

以前使用此代码的图像:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
   {
       UIImage *image = [UIImage imageWithData:self.responseData];
       self.thumbImageView.image = image;
   }

现在我不知道如何使用视频,请任何人都可以帮助我

提前致谢

2 个答案:

答案 0 :(得分:1)

试试这个

setDataSource:方法

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

     NSURL *url =[NSURL URLWithString:inVideosObj.video];
     MPMoviePlayerViewController *videoDeatilView = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
     //now you can present this videoDeatilView and 
     //[videoDeatilView.moviePlayer play]; will play the video
}

答案 1 :(得分:1)

self.responseData是NSMutableData,但MPMoviePlayerController需要url才能加载视频。

所以,首先你必须从数据中获取url-string。

NSString *url =[NSString stringWithUTF8String:[responseData bytes]]
MPMoviePlayerController *play = [[MPMoviePlayerController    alloc]initWithContentURL:[NSURL urlWithString:url]];
//Now present the MPMoviePlayerController