【问题标题】:Unable to render videos using XML parser无法使用 XML 解析器呈现视频
【发布时间】:2011-12-10 12:51:24
【问题描述】:

这是我的实现,我当然已经在头文件中初始化了所有的属性和插座。我是 Xcode 和 Obj-c 编程的新手,并试图在 iOS5 模拟器上播放这些视频,但它不起作用。任何帮助或指示将不胜感激。

#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

`

【问题讨论】:

    标签: objective-c nsmutablearray nsxmlparser ios5 sigabrt


    【解决方案1】:

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


    另外,请尝试在调试器中设置NSZombieEnabledMallocStackLoggingguard malloc。然后,当您的应用崩溃时,在 gdb 控制台中输入以下内容:

    (gdb) info malloc-history 0x543216
    

    0x543216 替换为导致崩溃的对象的地址,您将获得更有用的堆栈跟踪,它应该可以帮助您查明代码中导致问题的确切行。

    See this article for more detailed instructions.

    【讨论】:

    • 无论哪种方式..我似乎在我的主线程中收到一个程序收到 sigabrt 消息...调试器没有说太多...但我想知道这行是否有错误代码 (VideoMainViewController *) initWithXML{ self.videoArray = [NSMutableArray arrayWithCapacity:0];
    • 谢谢,我做了一个堆栈跟踪,它指向的行在下面。虽然我不知道错误可能是什么。 [self.view addSubview:thumbView];
    • 尝试将其更改为self.videoArray = [NSMutableArray array];。无论如何都没有真正需要初始化的能力。
    • 不。我在某处读到 arrayWithCapacity 不是必需的,所以已经尝试过了.. 应用程序在主线程中崩溃并显示消息 thread 1 program received signal sigabrt 尽管我已经链接了接口构建器和 .xib 文件中的所有内容..所以我想知道为什么我会收到这条消息。
    • 您也可以尝试将NSLog(@"%@", thumbView); 放在[self.view addSubview:thumbView]; 之前,以确保它不是nil
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多