實際上,我使用XMLParser
從服務器獲取了一個URL。我想在我的應用中播放此視頻網址。
現在我用`MPMoviePlayerController,但它不工作。請幫忙!如何在iPhone應用程序中從服務器播放視頻網址
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>
你爲什麼不告訴我們什麼不工作。顯示一些代碼。 –
這是我的xmlParser代碼和播放按鈕的動作 – islahul
你初始化之前的urlString的NSLog顯示是什麼? –