2

Actually, I get a url from server by using XMLParser. I want to play this video url in my app.
Now I used `MPMoviePlayerController, but its not working. Please help!

XMLParser.m

-(id) loadXMLByURL:(NSString *)urlString
{
videoNames      =[[NSMutableArray alloc]init];

videos          = [[NSMutableArray alloc] init];
NSURL *url      = [NSURL URLWithString:urlString];
NSData  *data   = [[NSData alloc] initWithContentsOfURL:url];
parser          = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname    namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:   (NSDictionary *)attributeDict
 {
 if ([elementname isEqualToString:@"items"]) 
{

}


 if ([elementname isEqualToString:@"video"]) 
 {
     NSLog(@"video");
 currentVideo = [Video alloc];
  }   
}


 - (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname 
 namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{

if ([elementname isEqualToString:@"video"]) 
{

   currentNodeContent2= [[currentNodeContent2 stringByReplacingOccurrencesOfString:@"+"    withString:@" "]
                               stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[videos addObject:currentVideo];
currentVideo.content2 = currentNodeContent2;


}
   if ([elementname isEqualToString:@"name"]) 
{
     currentNodeContent2= [[currentNodeContent2 stringByReplacingOccurrencesOfString:@"+" withString:@" "]
                          stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [videoNames addObject:currentVideo];
    currentVideo.content2 = currentNodeContent2;
    NSLog(@"%@",currentNodeContent2);
   }
  }


// in my class.m

 -(void)playButtonPressed1:(UIButton*)sender
 {
  UIButton *btn1 = (UIButton *)sender;

Video *currentVideo= [[xmlParservideo videos] objectAtIndex:btn1.tag];
   NSString *urlString=currentVideo.content;

NSURL *playURL=[[NSURL alloc]initWithString:urlString];

self.player =[[MPMoviePlayerController alloc]initWithContentURL
              :playURL];
      player.view.frame = CGRectMake(0,80,340,360);
    [self.view addSubview:player.view];

self.player.movieSourceType = MPMovieSourceTypeUnknown;

[self.player prepareToPlay];

[self.player play];
 }

my xml

  <items>
    <item>
      <pastor> Master Jojimon</pastor>  
       <video>
       http3A2F2Fvideo.google.com2Fgoogleplayer.swfFdocidD-675885207870876013326hl%3Den 
      </video>
      <name>Message by Master Jojimon</name>
        <lan>english</lan>
Pfitz
  • 7,226
  • 4
  • 36
  • 51
islahul
  • 194
  • 1
  • 11

1 Answers1

0

Its not working before that video string is not a valid url. A its pointing to an swf flash file which isn't a video. And B just typing in the url to Safari shows it as not a valid address.

If you were to handle for loading errors I am sure it would say its not a valid URL.

Ryan Poolos
  • 17,727
  • 4
  • 61
  • 95
  • http://www.youtube.com/embed/X_nJ7So9y04 this is working url , this also not play in my app – islahul Jun 23 '12 at 03:57
  • That isn't a video. That is a link to a flash player. Which also of course won't play in your app. You need a video to an actual video. An MP4 works best. – Ryan Poolos Jun 23 '12 at 14:45