objective c - Playing video in iPhone simulator with Media Player Framework -



objective c - Playing video in iPhone simulator with Media Player Framework -

i giving entire code below if helps anyway.....

#import "contentviewcontroller.h" #import "contentviewcontroller.h" #import "mediaplayerviewcontroller.h" #import "twitterviewcontroller.h" #import "youtubeviewcontroller.h" @implementation contentviewcontroller @synthesize imageview; @synthesize imageview1; @synthesize tableview; @synthesize navigationcontroller; @synthesize toolbar; @synthesize item; - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } homecoming self; } - (void)didreceivememorywarning { // releases view if doesn't have superview. [super didreceivememorywarning]; // release cached data, images, etc aren't in use. } #pragma mark - xmlparser delegate -(void)parsexmlfileaturl:(nsstring *)url{ nsurl *xmlurl = [nsurl urlwithstring:url]; rssparser = [[nsxmlparser alloc]initwithcontentsofurl:xmlurl]; [rssparser setdelegate:self]; [rssparser setshouldprocessnamespaces:no]; [rssparser setshouldreportnamespaceprefixes:no]; [rssparser setshouldresolveexternalentities:no]; [rssparser parse]; nslog(@"parsed"); } -(void)parserdidstartdocument:(nsxmlparser *)parser{ nslog(@"found file , started parsing"); } -(void)parser:(nsxmlparser *)parser parseerroroccurred:(nserror *)parseerror{ nsstring *errorstring = [nsstring stringwithformat:@"unable download feed website (error code %i)", [parseerror code]]; nslog(@"error parsing xml: %@", errorstring); uialertview *erroralert = [[uialertview alloc]initwithtitle:@"error loading content" message:errorstring delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil]; [erroralert show]; } -(void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname attributes:(nsdictionary *)attributedict{ currentelement = [elementname copy]; if ([elementname isequaltostring:@"channel"]) { rsselement = [[nsmutabledictionary alloc]init]; title = [[nsmutablestring alloc]init]; link = [[nsmutablestring alloc]init]; description = [[nsmutablestring alloc]init]; copyright = [[nsmutablestring alloc]init]; } } -(void)parser: (nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname{ if ([elementname isequaltostring:@"channel"]) { [rsselement setobject:title forkey:@"title"]; [rsselement setobject:link forkey:@"link"]; [rsselement setobject:description forkey:@"description"]; [rsselement setobject:copyright forkey:@"copyright"]; [item addobject:[rsselement copy]]; nslog(@"adding stories %@", title); } } -(void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string{ if ([currentelement isequaltostring:@"title"]) { [title appendstring:string]; }else if ([currentelement isequaltostring:@"link"]) { [link appendstring:string]; }else if ([currentelement isequaltostring:@"description"]) { [description appendstring:string]; }else if ([currentelement isequaltostring:@"copyright"]) { [copyright appendstring:string]; } } -(void)parserdidenddocument:(nsxmlparser *)parser{ nslog(@"all done"); nslog(@"item array has %d items", [item count]); [tableview reloaddata]; nslog(@"finished parsing"); } #pragma mark - view lifecycle - (void)viewdidload { [super viewdidload]; // additional setup after loading view nib. /* add together segmented controller */ if (segmentedcontrol == nil) { segmentedcontrol = [[uisegmentedcontrol alloc] initwithitems: [nsarray arraywithobjects:@"video", @"images", @"audio", nil]]; } [segmentedcontrol setframe:cgrectmake(55.0, 47.0, 180.0, 31.0)]; [segmentedcontrol setsegmentedcontrolstyle:uisegmentedcontrolstylebar]; [segmentedcontrol setwidth:70.0 forsegmentatindex:0]; [segmentedcontrol setwidth:70.0 forsegmentatindex:1]; [segmentedcontrol setwidth:70.0 forsegmentatindex:2]; [segmentedcontrol addtarget:self action:@selector(segmentclick:) forcontrolevents:uicontroleventvaluechanged]; [segmentedcontrol setmomentary:yes]; // [[[segmentedcontrol subviews]objectatindex:0]settintcolor:[uicolor blackcolor]]; [self.view addsubview:segmentedcontrol]; /* add together image view */ imageview1.image = [uiimage imagenamed:@"harry.png"]; /* add together page command */ pagecontrol = [[uipagecontrol alloc] init]; pagecontrol.frame = cgrectmake(120.0, 250.0, 100.0 ,10.0); pagecontrol.numberofpages = 5; pagecontrol.currentpage = 0; [self.view addsubview:pagecontrol]; /* customize table view */ tableview.backgroundcolor = [uicolor clearcolor]; imageview.image = [uiimage imagenamed:@"gradientbackground.png"]; item = [[nsmutablearray alloc]init]; if ([item count] == 0) { path = @"http://172.19.58.172/android/getapprovedlist.php?ip=172.19.58.172&type=video"; [self parsexmlfileaturl:path]; [tableview reloaddata]; nslog(@"returned %@", item); } headerlabel = [[uilabel alloc]initwithframe:cgrectmake(10.0, 270.0, 300.0, 14.0)]; headerlabel.text = @"latest videos"; headerlabel.textcolor = [uicolor whitecolor]; headerlabel.backgroundcolor = [uicolor clearcolor]; [self.view addsubview:headerlabel]; } /* assign command segment controller */ -(void)segmentclick:(uisegmentedcontrol *)segmentcontrol { if (segmentcontrol.selectedsegmentindex == 1){ if ([item count] == 0) { path = @"http://172.19.58.172/android/getapprovedlist.php?ip=172.19.58.172&type=image"; [self parsexmlfileaturl:path]; [tableview reloaddata]; headerlabel.text = @"latest images"; nslog(@"returned %@",item); } } else if (segmentedcontrol.selectedsegmentindex == 2){ if ([item count] == 0) { path = @"http://172.19.58.172/android/getapprovedlist.php?ip=172.19.58.172&type=audio"; [self parsexmlfileaturl:path]; [tableview reloaddata]; headerlabel.text = @"latest audios"; nslog(@"returned no items"); // [[[segmentedcontrol subviews]objectatindex:2]settintcolor:[uicolor blackcolor]]; } } else { if ([item count] == 0) { path = @"http://172.19.58.172/android/getapprovedlist.php?ip=172.19.58.172&type=video"; [self parsexmlfileaturl:path]; [tableview reloaddata]; headerlabel.text = @"latest videos"; nslog(@"returned %@", item); } // [[[segmentedcontrol subviews]objectatindex:0]settintcolor:[uicolor blackcolor]]; } } #pragma mark table view info source - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { nslog(@"this returned %@", item); homecoming item.count; } - (uitableviewcell *)tableview:(uitableview *)atableview cellforrowatindexpath:(nsindexpath *)indexpath{ static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier] autorelease]; } int feed = [indexpath indexatposition:[indexpath length] - 1]; cell.textlabel.text = [[item objectatindex:feed]objectforkey:@"title"]; cell.detailtextlabel.text = [[item objectatindex:feed]objectforkey:@"description"]; cell.accessorytype = uitableviewcellaccessorydisclosureindicator; homecoming cell; } - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{ nsstring *moviepath = [self.item objectatindex:indexpath.row]; nsurl *movieurl = [nsurl fileurlwithpath:moviepath]; nslog(@"item has %@", movieurl); playercontroller = [[mpmovieplayercontroller alloc]initwithcontenturl:movieurl]; [playercontroller play]; // mediaplayerviewcontroller *mediaview = [[mediaplayerviewcontroller alloc]initwithnibname:@"mediaplayerviewcontroller" bundle:nil]; // [self presentmodalviewcontroller:mediaview animated:yes]; } - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex{ if (buttonindex == 0) { sharealert = [[uiactionsheet alloc]initwithtitle:@"share to" delegate:self cancelbuttontitle:@"cancel" destructivebuttontitle:@"facebook" otherbuttontitles:@"twitter", nil]; [sharealert showinview:self.view]; } else if (buttonindex == 1){ nslog(@"button 2"); } } - (void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex{ if (buttonindex == 1) { twitterviewcontroller *twittercontroller = [[twitterviewcontroller alloc]initwithnibname:@"twitterviewcontroller" bundle:nil]; [self presentmodalviewcontroller:twittercontroller animated:yes]; } } -(void)movieplaybackdidfinish:(nsnotification *)notification{ mpmovieplayercontroller *movieplayercontroller = [notification object]; [movieplayercontroller.view removefromsuperview]; [movieplayercontroller release]; } - (void)viewdidunload { [super viewdidunload]; // release retained subviews of main view. // e.g. self.myoutlet = nil; } - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation { // homecoming yes supported orientations homecoming (interfaceorientation == uiinterfaceorientationportrait); } @end

changed didselectrow method following:

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{ moviepath = [[item objectatindex:indexpath.row]objectforkey:@"link"]; nslog(@"moviepath has %@", moviepath); movieurl = [nsurl urlwithstring:moviepath]; nslog(@"movieurl has %@", movieurl); viewcontroller = [[mpmovieplayerviewcontroller alloc]initwithcontenturl:movieurl]; [self presentmovieplayerviewcontrolleranimated:viewcontroller]; viewcontroller.movieplayer.moviesourcetype = mpmoviesourcetypestreaming; [playercontroller play]; viewcontroller = nil; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(movieplaybackdidfinish:) name:mpmovieplayerplaybackdidfinishnotification object:viewcontroller]; } - (void) movieplaybackdidfinish:(nsnotification*)notification { viewcontroller = [notification object]; [[nsnotificationcenter defaultcenter] removeobserver:self name:mpmovieplayerplaybackdidfinishnotification object:viewcontroller]; if ([viewcontroller respondstoselector:@selector(setfullscreen:animated:)]) { [viewcontroller.view removefromsuperview]; } }

now, on selecting row blank screen coming , application gets stuck there. video not played

any help in regard appreciated.

thanks in advance.

by looking @ code can tell you dont have reallocate item object.

if have allocated item object somewhere in class , stored values in not reallocate 1 time again did here:

item = [[nsmutablearray alloc]init]; nsstring *moviepath = [item objectatindex:indexpath.row];

by reallocating allocating new memory , in new memory there no objects present.

objective-c ios media-player

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -