开发者

Memory leaks when playing a video iPhone

开发者 https://www.devze.com 2023-03-22 04:21 出处:网络
I need to play a simple video on my app. I been looking on the internet on how to play a video and I found out that I need to import the MediaPlayer.framwork which I did. I have a Video named:

I need to play a simple video on my app. I been looking on the internet on how to play a video and I found out that I need to import the MediaPlayer.framwork which I did. I have a Video named:

Memory leaks when playing a video iPhone

and the code that I have in order to play it:

NSString *url = [[NSBundle mainBundle] 
                开发者_运维知识库 pathForResource:@"Final_Valores_Pacific" 
                 ofType:@"m4v"];


MPMoviePlayerController *player = 
                                [[MPMoviePlayerController alloc] 
                                initWithContentURL:[NSURL fileURLWithPath:url]];

I am missing the code to add it to a view but just that code creates a leak:

Memory leaks when playing a video iPhone

what is the right way of playing a video? how can avoid that memory leak?


When you alloc an object, you have to release it at the end:

// ...some code
NSString *url = [[NSBundle mainBundle] 
                 pathForResource:@"Final_Valores_Pacific" 
                 ofType:@"m4v"];


MPMoviePlayerController *player = 
                                [[MPMoviePlayerController alloc] 
                                initWithContentURL:[NSURL fileURLWithPath:url]];
// ...use player
[player release];


Are you getting this leak on the simulator? I got this on an app that I worked on in the past only on the simulator, but not on the iPhone.

There are similar questions about this too:

iPhone: OpenAL & AudioToolbox leak

0

精彩评论

暂无评论...
验证码 换一张
取 消