私はxcode 4.2を使用していて、iphoneアプリを構築しており、開いたときにオーディオストリームを再生するビューを持っています。
私が達成しようとするのは、アプリがバックグラウンドに入っても再生を続けることです。
私はstackoverflowや他の場所で見つかった可能な解決方法を試しましたが(利用可能なものも多数ありますが)、それを動作させることはできません。アプリケーションがバックグラウンドに入ると、オーディオが停止します。アプリを再び開くと、オーディオが継続します。私は何をしないのです
Required Background Modes -> App plays audio
&
Application does not run in background -> NO
iphone - バックグラウンドでオーディオストリームを再生する
:私のInfo.plistのIAでは
は2行を設定していますか?バックグラウンドでオーディオを再生し続けるために必要なものは何ですか?
ありがとうございます。
編集: AVAudio Frameworkの使用を提案して、この問題に関する多くの回答があります。 MPMoviePlayerControllerがバックグラウンドでストリームを再生できない可能性はありますか? AVAudioに変更する必要がありますか?
EDIT 2:
[OK]を達成するためには複雑すぎるようです。私は正確なコードを与えている、これが助けてくれることを願っています。
RadioStreamer.h
#import <UIKit/UIKit.h>
#import "MediaPlayer/MediaPlayer.h"
@interface RadioStreamer : UIViewController {
MPMoviePlayerController *player;
IBOutlet UIButton *playButton;
IBOutlet UIButton *pauseButton;
}
@property (nonatomic, retain) MPMoviePlayerController *player;
@property (nonatomic, retain) IBOutlet UIButton *playButton;
@property (nonatomic, retain) IBOutlet UIButton *pauseButton;
- (IBAction)playButtonPressed:(id)button;
- (IBAction)pauseButtonPressed:(id)button;
- (void) playAudio;
- (void) pauseAudio;
@end
RadioStreamer.m
#import "RadioStreamer.h"
#import "tabbartestAppDelegate.h"
@implementation RadioStreamer
@synthesize player;
@synthesize playButton;
@synthesize pauseButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
return self;
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[email protected]"";
// Do any additional setup after loading the view from its nib.
if (!self.player) {
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://s6.onweb.gr:8006/listen.pls"]];
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.frame = CGRectMake(55, 180, 200, 30);
player.backgroundView.backgroundColor = [UIColor clearColor];
player.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:player.view];
[player play];
}
}
- (void) playAudio {
if (player.playbackState != MPMoviePlaybackStatePlaying){
[player play];
}
}
- (void) pauseAudio {
if (player.playbackState == MPMoviePlaybackStatePlaying) {
[player pause];
}
}
- (IBAction)playButtonPressed:(id)button {
[self playAudio];
}
- (IBAction)pauseButtonPressed:(id)button {
[self pauseAudio];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)dealloc {
[self.player release];
[self.playButton release];
[self.pauseButton release];
self.player = nil;
self.playButton = nil;
self.pauseButton = nil;
}
@end
[iOS 5 - アプリ起動時の背景にオーディオファイルを再生する]の複製が可能です。(http://stackoverflow.com/questions/9199095/ios-5-play-audio-file-in-the-background - 起動時) –
ありがとうParth。このQでは、AVAudioPlayerが使用されますが、MPMoviePlayerControllerでは使用されません。あなたは違いがないと思いますか? – CrisDeBlonde
質問は同じです。唯一のアプローチは異なります。それがあなたのために働く場合、あなたのアプローチを変更することができます。 –