Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional iPhone and iPad Application Development
This is the forum to discuss the Wrox book Professional iPhone and iPad Application Development by Gene Backlin; ISBN: 978-0-470-87819-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional iPhone and iPad Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 19th, 2011, 10:58 PM
Registered User
 
Join Date: Feb 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chap. 8 errata? or version issues?

Hi Gene,
I am at Chapter 8, page 299 and 300 and notice two large blocks of code that are different in my Xcode file than the example in the book.

In your book on page 299, you show a couple code modifications for the file "iPadLibraryMoviePlayerAppDelegate.m" and you have listed the instance methods (if I have that naming correctly..still learning)

Code:
-(void)applicationDidEnterBackground: (UIApplication *)application {  
...

-(void)applicationWillEnterForeground: (UIApplication *)application {

..
but that does not exist in my code that was generated by my Xcode version 3.2.5 --Simulator - 4.2
so I do not know where to put your code in bold.
I am very interested in the video playing ability on the iPad and need to grab time codes so I was hoping that your book will help but now I am rather stuck to finish this exercise.
Thank you so much!!
C.J.
Reply With Quote
  #2 (permalink)  
Old February 20th, 2011, 08:31 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

These methods - which are delegate methods, not instance methods - are generated in the AppDelegate template, in this case, in iPodLibraryMoviePlayerAppDelegate.m To test this fact simply create a new View-based Application and look at the template for the AppDelegate. (Simply doing step 1 on p. 292 will demonstrate this.) If they are missing than something has gone wrong, since you should have not made any edits to this file up to this point. Are the other delegate methods present? (Running Xcode version 3.2.5)
Bob
Reply With Quote
  #3 (permalink)  
Old February 20th, 2011, 11:47 AM
Wrox Author
Points: 362, Level: 6
Points: 362, Level: 6 Points: 362, Level: 6 Points: 362, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 61
Thanks: 0
Thanked 9 Times in 7 Posts
Default

No you are not doing anything wrong at all. Good catch !!!

It should read "create a View-based application for the iPhone"...

The template for the iPhone and iPad are different, and as you found out, does not automatically supply these delegate methods.



ALSO..... when this book was published 4.0 and then soon after 4.1 was released. I have been keeping up with the SDK's so you, the reader, will not have to deal with the Base SDK Missing error when upgrading versions.

In 4.2, Apple no longer allows searching the iPod Library for Video content. So the traditional way I illustrate here will no longer work. I will be updating the project and will post an updated project ASAP. Gotta love change

The purpose of the chapter is to illustrate playing a movie, so the subject matter will remain the same, but the source of the video will no longer be the library, rather another source.

Stay tuned...
Reply With Quote
  #4 (permalink)  
Old February 20th, 2011, 01:26 PM
Registered User
 
Join Date: Feb 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank you Gene..
i did try the IPhone "view-based" and it did work like the book code shows.

I bought the book solely for the video section. You can imagine I am eagerly waiting for the update code sample. I have been through four books and the Apple docs and can see that there is some confusion as to how to work with the AVfoundation and MediaPlayer frameworks and using both to get the frame info I need. It was a lot easier in QTKit on MAC OS.
I like the fact that you have both frameworks illustrated in one app and can compare the player controls that are provided by them and your use of a table to pull in a selection of videos to choose from. Nice!..
I have used the MediaPlayer to make a smaller view to play the video in the ipad but what is not covered in any book is how to go deeper into the information in the frame, like to grab time codes. I see examples in books that use either one or the other of the frameworks but don't see if once you've used one framework to get your video playing and paused, like the MediaPlayer, can you use a different framework to get the timecode somehow. I don't know if the MPMovieTimeOptionExact will be the correct choice to grab and set the player head.
So I look forward to your examples of using some videos on the iPad to compare these frameworks!
Thank you for your speedy support!
C.J.
Reply With Quote
  #5 (permalink)  
Old February 20th, 2011, 03:00 PM
Wrox Author
Points: 362, Level: 6
Points: 362, Level: 6 Points: 362, Level: 6 Points: 362, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 61
Thanks: 0
Thanked 9 Times in 7 Posts
Default

Ok,

I have updated the code and will upload the new project in a bit.

Things to note:

Code:
	[self setMovieList:[NSArray arrayWithObjects:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"http://www.marizack.com/video/wroxbook/Chapter8Demo1.m4v", @"DemoMovie1", nil],
						[NSMutableDictionary dictionaryWithObjectsAndKeys:@"http://www.marizack.com/video/wroxbook/Chapter8Demo2.m4v", @"DemoMovie2", nil],
						nil]];
That now gets rid of the iPodLibrary that no longer works for video listing in 4.2. This will set up your list in the table view for you to choose from. The movies are streamed from my server.

Next:

To display the information in the table view for selections:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	NSDictionary *movie = [[self movieList] objectAtIndex:[indexPath row]];
	NSArray *keys = [movie allKeys];
	NSString *cellText = [keys objectAtIndex:0];
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	// Configure the cell.
	[[cell textLabel] setText:cellText];
	
    return cell;
}
Finally:

To chose the proper movie from the table view selection:

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	NSDictionary *movie = [[self movieList] objectAtIndex:[indexPath row]];
	NSArray *keys = [movie allKeys];
	NSString *key = [keys objectAtIndex:0];
	
	NSURL *aURL = [NSURL URLWithString:[movie objectForKey:key]];
	
	if([playerSwitch selectedSegmentIndex] == 0) {
		UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
		MediaPlaybackViewController *controller = [[MediaPlaybackViewController alloc] initWithNibName:@"MediaPlaybackViewController" bundle:nil];
		[controller setMovieURL:aURL];
		[controller setMovieTitle:[[cell textLabel] text]];
		[controller setStartPlayer:YES];
		[self setMediaPlaybackViewController:controller];
		
		[self presentModalViewController:controller animated: YES];
	}else {
		MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]
											   initWithContentURL:aURL];
		[self presentModalViewController:player animated:YES];
		[player release];
	}
	[tableView deselectRowAtIndexPath: indexPath animated: YES];
}
The change is now to get the movie URL from the NSDictionary we initialized in the viewDidLoad:

Code:
	NSDictionary *movie = [[self movieList] objectAtIndex:[indexPath row]];
	NSArray *keys = [movie allKeys];
	NSString *key = [keys objectAtIndex:0];
	
	NSURL *aURL = [NSURL URLWithString:[movie objectForKey:key]];

The complete listing:

Code:
//
//  iPodLibraryMoviePlayerViewController.m
//  iPodLibraryMoviePlayer
//
//  Created by Gene Backlin on 7/18/10.
//  Copyright Marizack Consulting 2010. All rights reserved.
//

#import "iPodLibraryMoviePlayerViewController.h"
#import "MediaPlaybackViewController.h"
#import "iPodLibrary.h"
#import <MediaPlayer/MediaPlayer.h>

@implementation iPodLibraryMoviePlayerViewController

@synthesize movieTableView;
@synthesize playerSwitch;
@synthesize movieList;
@synthesize mediaPlaybackViewController;


#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
	[self setMovieList:[NSArray arrayWithObjects:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"http://www.marizack.com/video/wroxbook/Chapter8Demo1.m4v", @"DemoMovie1", nil],
						[NSMutableDictionary dictionaryWithObjectsAndKeys:@"http://www.marizack.com/video/wroxbook/Chapter8Demo2.m4v", @"DemoMovie2", nil],
						nil]];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return YES;
}

#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [movieList count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	NSDictionary *movie = [[self movieList] objectAtIndex:[indexPath row]];
	NSArray *keys = [movie allKeys];
	NSString *cellText = [keys objectAtIndex:0];
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	// Configure the cell.
	[[cell textLabel] setText:cellText];
	
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	NSDictionary *movie = [[self movieList] objectAtIndex:[indexPath row]];
	NSArray *keys = [movie allKeys];
	NSString *key = [keys objectAtIndex:0];
	
	NSURL *aURL = [NSURL URLWithString:[movie objectForKey:key]];
	
	if([playerSwitch selectedSegmentIndex] == 0) {
		UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
		MediaPlaybackViewController *controller = [[MediaPlaybackViewController alloc] initWithNibName:@"MediaPlaybackViewController" bundle:nil];
		[controller setMovieURL:aURL];
		[controller setMovieTitle:[[cell textLabel] text]];
		[controller setStartPlayer:YES];
		[self setMediaPlaybackViewController:controller];
		
		[self presentModalViewController:controller animated: YES];
	}else {
		MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]
											   initWithContentURL:aURL];
		[self presentModalViewController:player animated:YES];
		[player release];
	}
	[tableView deselectRowAtIndexPath: indexPath animated: YES];
}

#pragma mark -
#pragma mark Memory management

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

- (void)viewDidUnload {
    // For example: self.myOutlet = nil;
	[self setMovieTableView:nil];
	[self setPlayerSwitch:nil];
	[self setMediaPlaybackViewController:nil];
}

- (void)dealloc {
	[movieTableView release];
	[playerSwitch release];
	[mediaPlaybackViewController release];
	
    [super dealloc];
}

@end


I will be posting the URL for the updated project for SDK 4.2 in my next post. Thanks again for bringing this to my attention !!!!


Take Care,
Gene

Last edited by gbacklin; February 20th, 2011 at 03:24 PM.
Reply With Quote
The Following User Says Thank You to gbacklin For This Useful Post:
c.J. (February 20th, 2011)
  #6 (permalink)  
Old February 20th, 2011, 03:14 PM
Wrox Author
Points: 362, Level: 6
Points: 362, Level: 6 Points: 362, Level: 6 Points: 362, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 61
Thanks: 0
Thanked 9 Times in 7 Posts
Default

Ok, the updated project for SDK 4.2 is now available at the following url:

Chapter8 iPodLibraryMoviePlayer for SDK 4.2

Just a note, there is no audio with these sample movies, as I wanted to put together something quick to keep you going with this chapter, but they are me showing you how to actually create this application from scratch. So a sneak preview of maybe a future podcast ????

Enjoy !
Reply With Quote
The Following User Says Thank You to gbacklin For This Useful Post:
c.J. (February 20th, 2011)
  #7 (permalink)  
Old February 20th, 2011, 03:29 PM
Registered User
 
Join Date: Feb 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Default

You are amazing!! Can't wait to load the code...
i can't thank you enough. How many times can I click that "thanks" button?!!
I will be watching all of your podcasts as soon as you do them. Let us know for sure when that happens and any other books and book signings "out West" !!
Thanks again!!!
C.J.
Reply With Quote
  #8 (permalink)  
Old February 20th, 2011, 03:34 PM
Wrox Author
Points: 362, Level: 6
Points: 362, Level: 6 Points: 362, Level: 6 Points: 362, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 61
Thanks: 0
Thanked 9 Times in 7 Posts
Default

No, I thank you for purchasing my book !!!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 5 Calendar - issues/comments kenj BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 2 May 17th, 2011 01:49 AM
Possible version issues? mikeofmany BOOK: Beginning Java 2, JDK 5 Edition 0 January 25th, 2011 09:39 PM
Chap 3 - some minor issues and comments kenj BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 20 January 8th, 2010 07:31 PM
Version issues Spider ASP.NET 3.5 Basics 3 March 2nd, 2009 02:00 PM
Errata for VB 2006 version Rich57 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 4 October 5th, 2007 12:14 PM



All times are GMT -4. The time now is 07:52 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.