Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-24-2012, 11:21 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 94
JamesCahall is on a distinguished road
Exclamation Media Player Audio-Only Bar Issue

Apparently I have something wrong with the settings for my media player because when running audio-only files it shows up like this:



Instead of this:



This is a problem because there is no DONE button and the user has to force quit the app to stop playing the file. Any ideas?

Thanks,
James
JamesCahall is offline   Reply With Quote
Old 01-24-2012, 11:23 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

It would help if you posted some code.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 01-25-2012, 10:54 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 94
JamesCahall is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
It would help if you posted some code.
Code:
@interface VideoViewController(Private) 
-(CGRect)setupLoadingViewFrame;

@end

@implementation VideoViewController

@synthesize moviePlayerController = _moviePlayerController;
@synthesize videoUrl = _videoUrl;
@synthesize loadingView = _loadingView;

- (id)init {
    //NSLog(@"VideViewController:init");
	self = [super init];
    if (self) {
		self.hidesBottomBarWhenPushed = YES;
    }
	return self;
}



- (void)dealloc
{
    NSLog(@"VideoViewController:dealloc");
    TT_RELEASE_SAFELY(_moviePlayerController);
    TT_RELEASE_SAFELY(_loadingView);
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad
{
    //NSLog(@"VideoViewController:viewDidLoad");
    [FlurryAnalytics logEvent:@"Playing video"]; 
    [super viewDidLoad];
    
    self.view.frame = self.navigationController.view.frame;
    
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    self.view.backgroundColor = [UIColor blackColor];
    
    [self setupMediaPlayer];
    
    _moviePlayerController.contentURL = _videoUrl;
    
    _moviePlayerController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
	[[NSNotificationCenter defaultCenter] addObserver:self
											 selector:@selector(playbackFinishedCallback:)
												 name:MPMoviePlayerPlaybackDidFinishNotification
											   object:_moviePlayerController];  
    
    [[NSNotificationCenter defaultCenter] addObserver:self
											 selector:@selector(loadStateChangedCallback:)
												 name:MPMoviePlayerLoadStateDidChangeNotification
											   object:_moviePlayerController];  
    
    // Testing   
    [[NSNotificationCenter defaultCenter] addObserver:self
											 selector:@selector(genericCallback:)
												 name:MPMoviePlayerPlaybackStateDidChangeNotification
											   object:_moviePlayerController];  
    
 	[_moviePlayerController prepareToPlay];
    
    [self showLoadingView];
    
    
    
}

- (void)viewDidUnload
{
    //NSLog(@"VideoViewController:viewDidUnload");
    [super viewDidUnload];
    
    [_loadingView removeFromSuperview];
    TT_RELEASE_SAFELY(_loadingView);
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:(68.0/255.0) green:(95.0/255.0) blue:(171.0/255.0) alpha:1.0];
    
}

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

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
       
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    _moviePlayerController.view.frame = self.view.frame;
    [UIView commitAnimations];
            
}

#pragma mark -
#pragma mark Movie Player Playback

-(void)playbackFinishedCallback:(NSNotification *)notification {
    //NSLog(@"VideoViewController:playbackFinishedCallback");
    
    [[NSNotificationCenter 	defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    
    [_moviePlayerController setControlStyle:MPMovieControlStyleEmbedded];
    
    // set our view so that we prevent a landscaped view when we exit the video
    ToonGogglesMVPAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    appDelegate.currentView = kOtherView;
    
    // We need to pop the movie player view and ourselves from the navigation controller
    [_moviePlayerController.view removeFromSuperview];
    if (IS_IPAD()) {
        self.navigationController.view.backgroundColor = [UIColor clearColor];
        [self.navigationController popViewControllerAnimated:YES];
        self.navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self.navigationController dismissModalViewControllerAnimated:YES];
    } else {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    //We need to set the status bar to default because media player custoized status bar with gray color and translucent. 
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
    // in case we were notified as a result of a network error/etc remove the loading view JIC
    [self hideLoadingView];
    
}

-(void) genericCallback:(NSNotification *)notification {
    //NSLog(@"VideoViewController:genericCallback");
    [_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
}

-(void)loadStateChangedCallback:(NSNotification *)notification {
    //NSLog(@"VideoViewController:loadStateChangedCallback");
    
    //NSLog(@"loadState [%i]",_moviePlayerController.loadState);
    if (_moviePlayerController.loadState & MPMovieLoadStatePlayable ) {
        //NSLog(@"Movie is ready to play.");
        [_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
        // Remove observer
        [[NSNotificationCenter 	defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
        [self hideLoadingView]; 
        [_moviePlayerController play];
    }
}

-(void)setupMediaPlayer {
    //NSLog(@"VideoViewController:setupMediaPlayer");
    
    CGRect viewFrame = self.view.frame;

    MPMoviePlayerController* mpc = [[MPMoviePlayerController alloc] init];
    self.moviePlayerController = mpc;
    TT_RELEASE_SAFELY(mpc);
    
    [[_moviePlayerController view] setFrame:viewFrame];
        
   	//[_moviePlayerController setControlStyle:MPMovieControlStyleNone];
   	[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
    [self.navigationController.view addSubview:[_moviePlayerController view]];
}

-(CGRect)setupLoadingViewFrame {
    CGRect rect = [self.view bounds];
    //NSLog(@"current frame size is [%f,%f,%f,%f]", rect.origin.x,rect.origin.y, rect.size.width, rect.size.height);   
    
    if (IS_IPAD()) {
        rect = self.navigationController.view.frame;
        //NSLog(@"current iPad frame size is [%f,%f,%f,%f]", rect.origin.x,rect.origin.y, rect.size.width, rect.size.height);
        
        rect = CGRectMake(0,0,1024,768);
    }
    return rect;
}




#pragma mark - Loading View 
-(void) showLoadingView {
    
    CGRect loadingFrame = [self setupLoadingViewFrame];
    CGRect cancelButtonFrame = CGRectMake(123,320,75,50);
    
    //check if iPad or not
    if (IS_IPAD()) {
        cancelButtonFrame   =  CGRectMake(loadingFrame.origin.x, loadingFrame.origin.y + 70, loadingFrame.size.width, loadingFrame.size.height);
        
        //NSLog(@"Cancel button  frame size is [%f,%f,%f,%f]", cancelButtonFrame.origin.x,cancelButtonFrame.origin.y, cancelButtonFrame.size.width, cancelButtonFrame.size.height);
    }
    
    TTActivityLabel* label = [[[TTActivityLabel alloc] initWithStyle:TTActivityLabelStyleBlackBox] autorelease];
    label.text = @"Loading...";
    [label sizeToFit];
    label.frame = loadingFrame;
    self.loadingView = label;
    
    UIButton *cancel                = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage* cancelNormalImage      = [UIImage imageNamed:@"cancelButton_normal.png"];
    UIImage* cancelHighlightedImage = [UIImage imageNamed:@"cancelButton_highlighted.png"];
    [cancel setImage:cancelNormalImage forState:UIControlStateNormal];
    [cancel setImage:cancelHighlightedImage forState:UIControlStateHighlighted];
    [cancel addTarget:self action:@selector(cancelButtonPressed)forControlEvents:UIControlEventTouchUpInside];
    cancel.showsTouchWhenHighlighted = YES;
    cancel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
    cancel.frame        = cancelButtonFrame;

    [self.loadingView addSubview:cancel];   
    [self.navigationController.view addSubview:_loadingView];
        
    // Use this event to tell our tabbar to hide itself
    [[NSNotificationCenter defaultCenter] postNotificationName:kEventWillPlayMovieFromHome object:nil]; 

}

-(void) cancelButtonPressed {
    [FlurryAnalytics logEvent:@"Video playback cancelled by user"]; 
    
    [_moviePlayerController stop];
    [self playbackFinishedCallback:nil];
    
    // Use this event to tell our tabbar to show itself
    [[NSNotificationCenter defaultCenter] postNotificationName:kEventMovieCancelButtonPressed object:nil]; 
    
    
}

-(void) hideLoadingView {
    if ( self.loadingView != nil) {
        [self.loadingView removeFromSuperview];
        self.loadingView = nil;
    }
}
@end
JamesCahall is offline   Reply With Quote
Old 01-26-2012, 08:27 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Since it's going to be fullscreen, why don't you use MPMoviePlayerViewController and just present it as a modal view controller?
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 01-26-2012 at 08:31 PM.
Domele is offline   Reply With Quote
Old 01-26-2012, 09:34 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 94
JamesCahall is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Since it's going to be fullscreen, why don't you use MPMoviePlayerViewController and just present it as a modal view controller?
The videos are being loaded from our kaltura server so we built it this way to allow for a loading screen to appear being the video is loaded. This allows the user to cancel if it is taking too long.

Note: when audio+video is playing, it looks completely normal with seek bar, done button, etc.
JamesCahall is offline   Reply With Quote
Old 01-26-2012, 09:42 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

I know it this technically shouldn't change anything but try this in your setupMediaPlayer method:
Code:
[_moviePlayerControllersetControlStyle:MPMovieControlStyleDefault];
[_moviePlayerControllersetControlStyle:MPMovieControlStyleFullscreen];
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Reply

Bookmarks

Tags
audio, bar, control, media player, play

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 401
12 members and 389 guests
7twenty7, Atatator, condor304, FrankWeller, glenn_sayers, iphonedevshani, MAMN84, mraalex, PowerGoofy, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:52 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0