Upload
takao-funami
View
11.661
Download
4
Embed Size (px)
DESCRIPTION
http://atnd.org/events/30549 第3回iphone_dev_jp 東京iPhone/Mac勉強会 のプレゼン資料です。
Citation preview
連続再生アプリをつくろうInside of Attacca
Takao FunamiMedia Technology Labs, Recruit co ltd
Twitter: @iRSSFaceBook: takao.funami
AVQueuePlayer,AVSessionのTips
12年7月21日土曜日
自己紹介をすこし
• フナミタカオ• リクルート メディアテクノロジーラボ所属• リクルートWebサービス開発担当 2007~• iOS 2008~• Android 2010年頃すこし
12年7月21日土曜日
iPhone
2009年頃の初期バージョンを開発http://mtl.recruit.co.jp/blog/2009/09/926foomoo_by_for_iphone.html
12年7月21日土曜日
iPad
2010年5月 じゃらん沖縄iPadhttp://mtl.recruit.co.jp/blog/2010/09/ipad.html
12年7月21日土曜日
Android
http://mtl.recruit.co.jp/blog/2010/01/android.html2010年1月 ホットペッパー for Adroid
12年7月21日土曜日
2011
http://itun.es/i6jS7pFhttp://itun.es/i6jY7dZ12年7月21日土曜日
2012 - Attaccaの音楽再生モジュールを開発しました
Share
PlayList
Search
Streaming Music
Ranking
Connection
12年7月21日土曜日
ところで、Attaccaインストールされましたよね?
•無料ミュージック2位• iTunesStore試聴連続再生•広告なし• JP,US,UKランキング対応•豊富なテーマ別プレイリスト•年代別Hits、フジロックetc
12年7月21日土曜日
ところで、Attaccaインストールされましたよね?
•無料ミュージック2位• iTunesStore試聴連続再生•広告なし• JP,US,UKランキング対応•豊富なテーマ別プレイリスト•年代別Hits、フジロックetc
本日:無料ミュージック28位 -まだのかた今すぐダウンロードお願いします!
12年7月21日土曜日
7/20 アップデート
12年7月21日土曜日
7/20 アップデート
•シャッフル機能追加• Twitter Framework対応
12年7月21日土曜日
本題
Attaccaの音楽再生モジュール開発の知見共有します
12年7月21日土曜日
iTunes試聴音楽連続再生アプリの基本要件
12年7月21日土曜日
iTunes試聴音楽連続再生アプリの基本要件
• 取得したリストから再生• 再生、停止• バックグラウンドでも再生• コントローラーに対応• ロック画面のコントローラーに対応
• 電話等の割り込み後に復帰
12年7月21日土曜日
音楽のリストを取得して、再生するしくみ
iTunes Search API
iTunes Store RSShttp://itunes.apple.com/jp/rss/itunes affiliates resources Search APIhttp://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
Music
JSON取得
iTunes Store RSS
Music Musicurl,nameimage..
Parser
AVQueuePlayer
AVPlayerItem AVPlayerItem AVPlayerItem
DataSorce
Musicクラスの配列
Music再生Manager
コントロールに反応
インスタンス化
12年7月21日土曜日
サーバーサイド(おまけ)
http://i2key.hateblo.jp/entry/playstudy3参照:第三回Playframework勉強会で発表してきました。
12年7月21日土曜日
1.連続再生にはAVQueuePlayerが便利
iTunes Search API Music
JSON取得
iTunes Store RSS
Music Musicurl,nameimage..
Parser
AVQueuePlayer
AVPlayerItem AVPlayerItem AVPlayerItem
DataSorce
Musicクラスの配列
Music再生Manager
コントロールに反応
インスタンス化
12年7月21日土曜日
AVPlayerItemの配列からAVQueuePlayerを作る
• // _palyURLs は再生したいURLの配列
• NSMutableArray *palyerItems = [NSMutableArray array];
int musicCount = [_playList count]; // palyerItems に playerItemを追加しまくる for (int i = index ; i < musicCount ; i++){ NSURL *url = [_palyURLs objectAtIndex:i]; if (url != nil){ AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url]; [palyerItems addObject:playerItem]; } } // AVQueuePlayerのインスタンスつくる AVQueuePlayer *player = [AVQueuePlayer queuePlayerWithItems:palyerItems]; [player play];
•-ストリーミング再生 - 3Gでも再生開始早い-先読み - 面倒なキャッシュを勝手にやってくれる うれしい※ iTunesアフィリの規約で、ダウンロード再生は禁止
簡単!
12年7月21日土曜日
AVQueuePlayerのコントロール
• AVPlayer• 再生 - (void)play;• 停止 - (void)pause;• 再生中のアイテム @property (nonatomic, readonly) AVPlayerItem *currentItem;
• AVQueuePlayer• 次の曲再生 - (void)advanceToNextItem;
弱点:戻るがない! & Fade IN/OUTできない
12年7月21日土曜日
AVQueuePlayer(AVPlayer)のステイタス監視
[self.player addObserver:self forKeyPath:@"status" options:0 context:&PlayerStatusContext];
[self.player addObserver:self forKeyPath:@"currentItem" options:0 context:&CurrentItemChangedContext];
[self.player addObserver:self forKeyPath:@"rate" options:0 context:&PlayerRateContext];
↑だけではたりない
AVPlayerItem *playerItem = [self.player currentItem];
playerItem.playbackLikelyToKeepUp
AVPlayerItemのステイタスもみる必要あり
もれがたくさんありそうなので、調査中です弱点:通信状態のエラーハンドリング不安
12年7月21日土曜日
2.バックグラウンドでも再生
• info.plist UIBackgroundModesをaudioに
<key>UIBackgroundModes</key> <array> <string>audio</string> </array>
• AVAudioSessionのカテゴリをAVAudioSessionCategoryPlaybackに
12年7月21日土曜日
AVQueuePlayer勉強のための必見のビデオ
• 405_exploring_av_foundation 2010 WWDCビデオ
12年7月21日土曜日
3.電話とかの割り込み後復帰
• AVAudioSessionDelegateに対応すればOK#pragma mark -#pragma mark Interruption event handling- (void)beginInterruption{ if (self.playingMusic){ self.shouldResume = YES; }else{ self.shouldResume = NO; } self.playingMusic = NO;}
- (void)endInterruptionWithFlags:(NSUInteger)flags{ if (flags == AVAudioSessionInterruptionFlags_ShouldResume){ [[AVAudioSession sharedInstance] setActive: YES error: nil]; if (self.shouldResume){ [self play]; } } }
biginで状態保持して、endで状態におおじて必要な場合は再生再開
12年7月21日土曜日
4.リモートコントローラ対応-‐ (void) viewDidAppear:(BOOL)animated { if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginReceivingRemoteControlEvents)]){ [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder]; }}
-‐ (void) viewWillDisappear:(BOOL)animated { [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; [self resignFirstResponder];}
#pragma mark -#pragma mark Remote-control event handling// Respond to remote control events- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent { if (receivedEvent.type == UIEventTypeRemoteControl) { switch (receivedEvent.subtype) { case UIEventSubtypeRemoteControlTogglePlayPause: [self playOrPause]; break; case UIEventSubtypeRemoteControlPreviousTrack: [self prev]; break; case UIEventSubtypeRemoteControlNextTrack: [self next]; break; default: break; } }}
12年7月21日土曜日
5.ロック画面へのアートワーク表示- (NSDictionary *)songInfo{ NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init]; [songInfo setObject:self.title forKey:MPMediaItemPropertyTitle]; [songInfo setObject:self.author forKey:MPMediaItemPropertyArtist]; [songInfo setObject:self.album forKey:MPMediaItemPropertyAlbumTitle]; if (self.artwork){ [songInfo setObject:self.artwork forKey:MPMediaItemPropertyArtwork]; }else{ [songInfo setObject:[[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"glay.png"]] forKey:MPMediaItemPropertyArtwork]; } /* コピーしたほうが、安全かもと思い、コピー */ return [NSDictionary dictionaryWithDictionary:songInfo];}
- (void)updatePlayingInfo{ Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter"); if (playingInfoCenter) { NSDictionary *songInfo = [self.currentMusic songInfo]; [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo]; //NSLog(@"songInfo:%@",songInfo); }}
MPNowPlayingInfoCenterを使えばOK ただし iOS5.0以上
12年7月21日土曜日
これらのサンプルソース作成中です
• あとで gitあげます
12年7月21日土曜日
今後
• Fade IN / OUTしたいとおもうので、根本的に見直す必要があるかもとおもっています。
• でも、とりあえず、AVQueuePlayer快適なので、簡単アプリ作成にはGood
• iTunesの規約もあって、オフライン対応していませんが、自分用には、オフライン対応して、朝の電車でも快適連続再生
12年7月21日土曜日
最後に
• AVQueuePlayer快適なのでAttaccaよろしくおねがいします
12年7月21日土曜日