2011-10-18 26 views
0

这是我的实现,当然我已经初始化了头文件中的所有属性和插座。我是Xcode和Obj-c编程的新手,并尝试在iOS5模拟器上播放此视频,该视频不工作。任何帮助或指针将不胜感激。无法使用XML解析器呈现视频

#import "VideoMainViewController.h" 
#import "HotdogAppDelegate.h" 
#import "Video.h" 

@implementation VideoMainViewController 
@synthesize videoArray; 
@synthesize currentCateogry; 
@synthesize secondView; 
@synthesize thumbContainerView; 

NSXMLParser *xmlParser; 

-(VideoMainViewController *) initWithXML{ 
self.videoArray = [NSMutableArray arrayWithCapacity:0]; 
self.secondView = [[VideoSecondViewController alloc] init]; 
[self.view addSubview:thumbView]; 


NSString* path = [[NSBundle mainBundle] pathForResource:@"videos" ofType:@"xml"]; 
NSURL *url = [NSURL fileURLWithPath:path]; 
xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; 
[xmlParser setShouldProcessNamespaces:YES]; 
[xmlParser setDelegate:self]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVideoBackClick) name:@"onVideoBack" object:self.secondView]; 

HotdogAppDelegate *application = (HotdogAppDelegate *)[[UIApplication sharedApplication] delegate]; 
[application addViewController:&self]; 
[super init]; 
return self; 
} 


-(void)viewDidLoad { 
[super viewDidLoad]; 
} 

-(void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    } 

-(void)viewDidUnload { 
[super viewDidUnload]; 
} 

-(IBAction) onMayoClick:(id)sender{ 
[self.secondView loadVideos:(NSMutableArray *)[self.videoArray objectAtIndex:0]]; 
} 
-(IBAction) onMustardClick:(id)sender{ 
[self.secondView loadVideos:(NSMutableArray *)[self.videoArray objectAtIndex:1]]; 
    } 
    -(IBAction) onKetchupClick:(id)sender{ 
[self.secondView loadVideos:(NSMutableArray *)[self.videoArray objectAtIndex:2]]; 
    } 

    -(void)stopVideo{ 
[secondView stopVideo]; 
    } 

    -(void) reset{ 
[self.view addSubview:thumbView]; 
thumbView.alpha = 1; 
if(self.secondView.view.superview){ 
[self.secondView.view removeFromSuperview]; 
} 
    } 


    -(void)parserDidEndDocument:(NSXMLParser *)parser{ 
[xmlParser release]; 
    } 

    -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
    namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
attributes:(NSDictionary *)attributeDict { 

if([elementName isEqualToString:@"Mayo"]|| 
    [elementName isEqualToString:@"Mustard"]|| 
    [elementName isEqualToString:@"Ketchup"]) { 

    self.currentCateogry = [NSMutableArray arrayWithCapacity:0]; 
    [self.videoArray addObject:self.currentCateogry]; 

}else if ([elementName isEqualToString:@"video"]) { 
    Video *video = [[Video alloc] init]; 
    video.thumb = [attributeDict objectForKey:@"thumb"]; 
    video.mp4 = [attributeDict objectForKey:@"mp4"]; 
    video.title = [attributeDict objectForKey:@"title"]; 

    [self.currentCateogry addObject:video]; 

} 
    } 

    -(void) dealloc{ 

for (NSObject *video in self.videoArray) { 
    [video dealloc]; 
} 

[self.videoArray removeAllObjects]; 
[self.videoArray dealloc]; 
[self.secondView dealloc]; 
[xmlParser dealloc]; 
    [super dealloc]; 
    } 


    @end 

`

回答

0

影片通常不会在模拟器玩。您可能需要在实际设备上运行它才能正常播放视频。


另外,尽量在调试器设置NSZombieEnabledMallocStackLoggingguard malloc。然后,当你的应用程序崩溃,在gdb的控制台输入:

(gdb) info malloc-history 0x543216 

替换0x543216与导致崩溃的对象的地址,你会得到一个更加有用的堆栈跟踪,它应该帮助你查明导致问题的代码中的确切行。

See this article for more detailed instructions.

+0

无论哪种方式..我似乎得到一个程序在我的主线程收到SIGABRT消息...调试器不会说太多...但我想知道是否有这一行的错误code(VideoMainViewController *)initWithXML {self.videoArray = [NSMutableArray arrayWithCapacity:0]; – irookie

+0

谢谢,我做了一个堆栈跟踪,它指向的路线如下。虽然我不知道错误可能是什么。 '[self.view addSubview:thumbView];' – irookie

+0

尝试将其更改为'self.videoArray = [NSMutableArray array];'。无论如何,没有真正的需要启动容量。 – chown