iPhoneでは簡単にムービーを再生する事の出来るAPIが用意されています。
MediaPlayer.frameworkを利用して再生します。
再生できるビデオフォーマット
H.264 Baseline Profile
o 最大 640x480 最大30fps (Bフレームはサポートされない)
o 最大 1.5MBps
o 音声 最大160kbps AAC-LC 48Khz
MPEG4 Part2 Simple Profile
o 最大 640x480 最大30fps
o 最大2.5Mbps
o 音声は最大160kbpsのAAC-LC 48kHz
対応拡張子
o mp4/m4v/mov/.3gp
MyMoviePlayer.h
#import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h>
@interface MyMoviePlayer : UIView { }
@end |
MyMoviePlayer.m
#import "MyMoviePlayer.h"
@interface MyMoviePlayer (PrivateMethods)
- (void) startPlayback;
@end
@implementation MyMoviePlayer
- (void)init { }
- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; [super dealloc]; }
- (void) startPlayback { NSString *path = [[NSBundle mainBundle] pathForResource:@"hoge" ofType:@"m4v"]; MPMoviePlayerController *moviePlayer; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; moviePlayer.scalingMode = MPMovieScalingModeAspectFill;//フル画質 // moviePlayer.movieControlMode = MPMovieControlModeHidden; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; [moviePlayer play]; }
- (void)myMovieFinishedCallback:(NSNotification*)aNotification { MPMoviePlayerController *theMovie = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie]; [theMovie release]; }
@end |
とりあえずこれで再生は出来るようになります。
ただ、これだけでは再生が終わってもメモリが解放されないのですよね。
何をどうやって解放すれば良いのかが分かりません。
何か解放の仕方を知っている方がいましたらコメントで教えていただけるとうれしいです。
posted by ラキシス at 19:31
|
Comment(0)
|
TrackBack(0)
|
iPhoneプログラミング
|

|