2

实际上,我使用XMLParser. 我想在我的应用中播放这个视频网址。
现在我使用了`MPMoviePlayerController,但它不起作用。请帮忙!

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];
 }

我的 xml

  <items>
    <item>
      <pastor> Master Jojimon</pastor>  
       <video>
       http3A2F2Fvideo.google.com2Fgoogleplayer.swfFdocidD-675885207870876013326hl%3Den 
      </video>
      <name>Message by Master Jojimon</name>
        <lan>english</lan>
4

1 回答 1

0

在该视频字符串不是有效的 url 之前它不起作用。它指向一个不是视频的 swf flash 文件。而 B 只是在 Safari 中输入 url 将其显示为无效地址。

如果您要处理加载错误,我相信它会说它不是有效的 URL。

于 2012-06-22T13:59:12.590 回答