Note that there are some explanatory texts on larger screens.

plurals
  1. POAudio pausing when device switches off NOT PLAYING IN BACKGROUND Xcode 4.2
    text
    copied!<p>Help me on this issue please. I am new to Xcode, so please explain to me in detail.</p> <p>In my app there is audio and video included, but I have only included the audio coding.</p> <p>Audio file is 30 min. long. Audio pauses when device switches off, NOT PLAYING IN BACKGROUND basically.</p> <p>I have tested this on my iPhone 4S. It starts playing for about 1 min., then phone goes to sleep as normally it does. Suddenly audio stopped playing. When you switch ON the phone, it starts playing again where it was stopped.</p> <p>I want the audio to play continuously even the phone goes to sleep. Thanks.</p> <p>This is the h file</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;MediaPlayer/MediaPlayer.h&gt; @interface Mynewpage4 : UIViewController { NSString *urlname; MPMoviePlayerController *player; } @property(nonatomic,retain)NSString *urlname; @end </code></pre> <p>This is m file</p> <pre><code>#import "Mynewpage4.h" #import &lt;MediaPlayer/MediaPlayer.h&gt; @implementation Mynewpage4 @synthesize urlname; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (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 - (void)viewDidLoad { NSString *url = [[NSBundle mainBundle] pathForResource:urlname ofType:@"mp3"]; player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; player.view.frame = CGRectMake(0, 0, 320, 370); [self.view addSubview:player.view]; [player play]; [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } -(void)viewDidDisappear:(BOOL)animated { NSLog(@"hi"); [player stop]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); } @end </code></pre> <p>This is my h file</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "Custom_cell.h" @interface Newpage4 : UIViewController{ NSMutableArray *mydata; NSMutableArray *myaudio; // IBOutlet Custom_cell *owncell } @end </code></pre> <p>This is m file</p> <pre><code>#import "Newpage4.h" #import "Custom_cell.h" #import "Mynewpage4.h" @implementation Newpage4 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (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 - (void)viewDidLoad { mydata = [[NSMutableArray alloc]initWithObjects:@"great",nil]; myaudio = [[NSMutableArray alloc]initWithObjects:@"1",nil]; [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [mydata count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Custom_cell"; Custom_cell *cell = (Custom_cell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (indexPath.section == 0) {} if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"Custom_cell" owner:self options:nil]; //cell = [[[Custom_cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; for (id currentObject in topLevelObjects) { if ([currentObject isKindOfClass:[UITableViewCell class]]) { cell = (Custom_cell *) currentObject; //cell.backgroundView.backgroundColor = [UIColor clearColor]; break; } } } cell.lbl.text = [mydata objectAtIndex:indexPath.row]; return cell; // [myString release]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Mynewpage4 *page = [[Mynewpage4 alloc]init]; page.urlname = [myaudio objectAtIndex:indexPath.row]; [self.navigationController pushViewController:page animated:YES]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload