developing Radio ios App - objective-c

I have a problem when I test my radio iOS app on real device its working well but when the screen or the device is turned off, the radio is stopped and turn off why this happen?
and how to make activity indicator view stopped moving and hide it when the radio is open and finish loading???
(void)viewDidLoad
{
[super viewDidLoad];
timer=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(uodatetimer) userInfo:nil repeats:YES];
player = [[MPMoviePlayerController alloc] initWithContentURL:
[NSURL URLWithString:#"http://46.43.64.50:8008/AJYAL.m3u"]];
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.hidden = YES;
[self.view addSubview:player.view];
[player prepareToPlay];
[player play];
// player.useApplicationAudioSession=NO;
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);
spinner.center=self.view.center;
[spinner startAnimating];
[self.view addSubview:spinner];
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:
CGRectMake(0, 0, 105, 15)] autorelease];
volumeView.center = CGPointMake(152,372);
[volumeView setShowsVolumeSlider:YES];
[volumeView setShowsRouteButton:YES];
[volumeView sizeToFit];
[self.view addSubview:volumeView];
}

You need to do 2 things to enable audio playback in the background:
Add the "Required background modes" key to your Info.plist file with the "App plays audio" value.
Set the audio session category to AVAudioSessionCategoryPlayback and activate the audio session:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];

To be able to have it playing in background you need to enable in project .plist file UIBackgroundModes or Required Background Modes in human readable format and in array for first string row write audio. That will make your app running after the screen is off and while in background.

in the yourProject-pList add this row

Related

iOS 7 Video not playing MPMoviePlayerController

This code is working perfect in iOS 8 . but unable to play video in iOS7.The player shows up but plays nothing.Thanks
NSString *url = #"http://.../playlist.m3u8";
NSURL *streamURL = [NSURL URLWithString:url];
self.streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];
self.streamPlayer.controlStyle= MPMovieControlStyleFullscreen;
self.streamPlayer.movieSourceType = MPMovieSourceTypeStreaming;
self.streamPlayer.shouldAutoplay = YES;
[self.view addSubview:self.streamPlayer.view];
[self.streamPlayer prepareToPlay];
[self.streamPlayer play];
From the documentation:
When you add a movie player’s view to your app’s view hierarchy, be sure to size the frame correctly, as shown here:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
Try to set the frame of your video player.

disable user interaction in MPMoviePlayerController

I need to disable total user interaction during a play of a litle video, i already tried to set the style of the control to none : MPMovieControlStyleNone, and put a UIView above the MPMoviePlayerController, but when i pinch the video disappears, and the sound still playing, like i dismissed the video, but it still playing on the background, plus the user interaction is disabled.
Heres how i do:
-(IBAction)startGame:(id)sender
{
NSURL * url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Teste" ofType:#"m4v"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
mBlankView = [[UIView alloc] initWithFrame:moviePlayer.view.frame];
mBlankView.userInteractionEnabled = NO;
[mBlankView setMultipleTouchEnabled:NO];
[mBlankView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:mBlankView];
}
To disable Movieplayer control completely u need to disable your movieplayers view userinteraction as follows:
moviePlayer.view.userInteractionEnabled = NO;

MPMoviePlayerViewController not showing volume slider?

I am playing the video from the url:
MPMoviePlayerViewController *m = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
if([m.moviePlayer respondsToSelector:#selector(setAllowsAirPlay:)])
m.moviePlayer.allowsAirPlay = YES;
[self presentMoviePlayerViewControllerAnimated:m];
It is playing, but there is no volume control slider. Is it possible to add volume control?
You can use MPVolumeView object.
volume = [[MPVolumeView alloc] initWithFrame: rect];
[self addSubview:volume];

Movie player iOS5 play symbol over view

I have been trying to figure out how to get the "play symbol" on top of my movie view, so that the user just have to press that and the video will start. Anybody know how to implement that?
-(void)viewDidLoad
{
//Video player
NSString *url = [[NSBundle mainBundle] pathForResource:self.navigationItem.title ofType:#"mov"];
_player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath: url]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:_player];
_player.view.frame = CGRectMake( 350, 200, 400, 400);
[self.view addSubview:_player.view];
}
//Plays the movie once the "Play" button is pressed
-(IBAction)playMovie
{
[_player play];
}
//Exits fullscreen when movie is finished
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
_player.fullscreen = NO;
}
You can either create an IBOutlet for your button or you will have to add the play button yourself via code like this... (in order to access it via code.)
// Add play button
playButton = [[UIButton alloc] initWithFrame:CGRectMake(53, 212, 214, 36)];
[playButton setBackgroundImage:[UIImage imageNamed:#"playButton.png"] forState:UIControlStateNormal];
[playButton addTarget:self action:#selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];
[[self view] addSubview:playButton];
and once you are done adding the movieplayer to the view.... you need to bring the playbutton to the front like ....
[self.view bringSubviewToFront:playButton];
remember this to be done once you have added the movieplayer to the view...
source ... http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html

MPMoviePlayerController controls when opened in a UIModalPresentationFormSheet style modal and the user makes the video fullscreen

In my iPad app, I have a UIButton that is calling an IBAction to call a view controller as a modal to show a video in. I wanted the modal to appear as 720x405, and that part seems to work out okay. Here is the IBAction code the button is executing:
-(IBAction)videoPlayerTest:(id)sender {
VideoModalViewController *vc = [[VideoModalViewController alloc] initWithNibName: #"VideoModalViewController" bundle: nil];
vc.fileName = #"testvideo.m4v";
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated: YES];
vc.view.superview.frame = CGRectMake(0, 0, 720, 405);
vc.view.superview.center = self.view.center;
[vc release];
}
The modal comes up where I want it, and the controls respond on the MPMoviePlayerController; the jog bar, pause, play, etc. but if the user taps on the fullscreen button, the video does go fullscreen alright, but after that the MPMoviePlayerController won't respond to any subsequent taps on the player controls. If I remove the modalPresentationStyle line it will work, but the modal appears on a fullscreen view instead of the 720x405 modal like I want. I've added Observers to try resizing the frame and recenter it when the user makes the movie controller fullscreen and back to windowed, but it didn't appear to help at all. Here is that code.
- (void)willEnterFullscreen:(NSNotification*)notification {
NSLog(#"willEnterFullscreen");
[self setModalPresentationStyle:UIModalPresentationFullScreen];
self.view.frame = CGRectMake(0, 0, 1024, 768);
self.view.center = self.view.center;
}
- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(#"willExitFullscreen");
[self setModalPresentationStyle:UIModalPresentationFormSheet];
self.view.frame = CGRectMake(0, 0, 720, 405);
self.view.center = self.view.center;
}
- (void)playMovie {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 720, 405);
moviePlayer.view.backgroundColor = [UIColor grayColor];
[moviePlayer prepareToPlay];
[moviePlayer play];
}
This is my first post-- hope I did it right and provided enough information about the problem I'm having.
I've solved my problem. I was unaware of MPMoviePlayerViewController and I created that and used that as my modal instead. It works great.
-(void)playVideo:(NSString *)fileName {
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentModalViewController:mpViewController animated:NO];
[[mpViewController moviePlayer] play];
}
-(IBAction)videoPlayerTest:(id)sender {
[self playVideo:#"testvideo.m4v"];
}
Thought I'd post what I came up with just in case somebody else encounters the same