2011-10-18 21 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