Reputation: 17
hi I'm trying to view the videos from my server for that i have stored the video url in mysql database using the json and php code I'm passing the url to the iOS but now I'm getting some problem here
this is the code i have used to fetch the video url to view in the table cell
table cell .m file code:
#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
after coding this im not able to play vedio in my table cell
im getting issue:
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;
}
like this in my console so pls help me with this
thanks in advance...
Upvotes: 0
Views: 1493
Reputation: 56
This error appear when the URL is broken. You said that you use JSON on your service, so as I understand in this line
NSString *url =[NSString stringWithUTF8String:[self.responseData bytes]];
you receive JSON instead of URL. So first of all, check in log what you receive, if it's really JSON use next example:
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];
}
Upvotes: 1