تشغيل الفيديو في الشاشة حجم مخصص - الرأي في اي فون
-
07-07-2019 - |
سؤال
والمستخدم افترض الصنابير على زر ويبدأ الفيديو للعب. الآن عندما يلعب الفيديو، فإنه دائما في وضع ملء الشاشة.
يجب أن يكون لعبت الفيديو في وضع عمودي (ولكن عادة لعبت الفيديو في وضع أفقي). كيف يمكنني أن أفعل هذا؟
المحلول
@interface MPMoviePlayerController (extend)
-(void)setOrientation:(int)orientation animated:(BOOL)value;
@end
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
if (moviePlayer)
{
[self.moviePlayer play];
}
وسيتم رفض هذا الحل من قبل شركة آبل، كما setOrientation لاعب الفيلم هو API الخاصة. عليك أن تكون حذرا، لكنها قد تعمل على أجهزة iPhone Jailbroke.
نصائح أخرى
وفقط تحديثا، فإن أحدث فون SDK 3.2+ الآن تسمح للمبرمجين لعرض الفيديو في أي حجم المطلوب والتوجيه، وتقديم أية MPMoviePlayerView، وهو خاصية من MPMoviePlayerController، فإن هذا الرأي يكون شريط الفيديو، الذي يمكن إضافة باعتباره subview إلى وجهة نظركم.
ومن مستندات موثقة لا أعتقد أن هذا ممكن باستخدام المدمج في مشغل وسائط
وجرب هذا. لقد وجدت شيئا جديدا.
@interface MPMoviePlayerController (extend)
-(void)setOrientation:(int)orientation animated:(BOOL)value;
@end
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
if (moviePlayer)
{
[self.moviePlayer play];
}
إليك ما فعلته. إضافة NSNotification لإعلامك عند تحميلها مسبقا من انتهاء الفيديو.
- (void)playVideoUrl:(NSString *)videoUrl {
NSURL *url = [NSURL URLWithString:videoUrl];
MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
//MPMoviePlayerContentPreloadDidFinishNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedPreloading:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
واستدعاء محدد:
-(void)myMovieFinishedPreloading:(NSNotification*)aNotification {
NSArray *windows = [[UIApplication sharedApplication] windows];
UIWindow *moviePlayerWindow = nil;
if ([windows count] > 1)
{
moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
}
CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);
transform = CGAffineTransformRotate(transform, -90.0f*M_PI/180.0f);
[moviePlayerWindow setTransform:transform];
}