如何在iphone中以横向模式播放视频

Posted

技术标签:

【中文标题】如何在iphone中以横向模式播放视频【英文标题】:how to play videos in Landscape mode in iphone 【发布时间】:2014-06-13 06:45:32 【问题描述】:

任何人都可以帮助我,我不使用MPMoviePlayerController 开玩笑说我在四个单元格中使用UItableView

#import "VSChannelListViewController.h"
#import "VSPlayerViewController.h"

@interface Channel : NSObject 
    NSString *_name;
    NSString *_urlAddress;
    NSString *_description;
    NSDictionary *_options;


@property (nonatomic, readonly) NSString *name;
@property (nonatomic, readonly) NSString *urlAddress;
@property (nonatomic, readonly) NSString *description;
@property (nonatomic, readonly) NSDictionary *options;

+ (id)channelWithName:(NSString *)name addr:(NSString *)addr description:(NSString *)description options:(NSDictionary *)options;
- (id)initWithName:(NSString *)name addr:(NSString *)addr description:(NSString *)description options:(NSDictionary *)options;

@end

@implementation Channel

@synthesize name = _name;
@synthesize urlAddress = _urlAddress;
@synthesize description = _description;
@synthesize options = _options;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
        // Custom initialization
        self.title = @"Channel List";
        _channelList = [[NSMutableArray array] retain];

       Channel *c1 = [Channel channelWithName:@"TEST" addr:@"rtsp://202.65.154.103:1935/live/text.stream" description:@"justin reporter" options:[NSDictionary dictionaryWithObject:VSDECODER_OPT_VALUE_RTSP_TRANSPORT_TCP forKey:VSDECODER_OPT_KEY_RTSP_TRANSPORT]];
        [_channelList addObject:c1];

        Channel *c2 = [Channel channelWithName:@"Cartoon TV" addr:@"rtsp://ws2.gpom.com/cartoon" description:@"justin reporter Pavan" options:[NSDictionary dictionaryWithObject:VSDECODER_OPT_VALUE_RTSP_TRANSPORT_TCP forKey:VSDECODER_OPT_KEY_RTSP_TRANSPORT]];
        [_channelList addObject:c2];

        Channel *c3 = [Channel channelWithName:@"Sky-news" addr:@"rtsp://202.65.154.103:1935/live/text.stream" description:@"justin reporter Alapati" options:[NSDictionary dictionaryWithObject:VSDECODER_OPT_VALUE_RTSP_TRANSPORT_TCP forKey:VSDECODER_OPT_KEY_RTSP_TRANSPORT]];
        [_channelList addObject:c3];

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVSPlayerStateChanged:) name:kVSPlayerStateChangedNotification object:nil];
    
      return self;
;

然后使用 tableView 方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    return [_channelList count];


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    static NSString *cellId = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) 
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId] autorelease];

        UIView *topLine = [[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)] autorelease];
        topLine.backgroundColor = [UIColor colorWithRed:1.1 green:1.1 blue:1.11 alpha:0.5];
        [cell.contentView addSubview:topLine];

        UIView *bottomLine = [[[UIView alloc] initWithFrame:CGRectMake(0.0f, 63.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)] autorelease];
        bottomLine.backgroundColor =[UIColor colorWithRed:0.78 green:0.78 blue:0.79 alpha:0.5];
        [cell.contentView addSubview:bottomLine];

        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:18];
        cell.detailTextLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:16];
    

    Channel *channel = [_channelList objectAtIndex:indexPath.row];
    cell.textLabel.text = [channel name];
    cell.detailTextLabel.text = [channel description];

    return cell;


- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath 
    cell.backgroundColor = [UIColor colorWithRed:0.94 green:0.94 blue:0.95 alpha:1.0];

然后在

中使用didSelectRowAtIndexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    Channel *channel = [_channelList objectAtIndex:indexPath.row];
    NSString *urlString = [channel urlAddress];
    NSDictionary *options = [channel options];

    VSPlayerViewController *playerVc = [[[VSPlayerViewController alloc] initWithURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] decoderOptions:options] autorelease];
    playerVc.barTitle = [channel name];
    playerVc.statusBarHidden = YES;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
    if ([[[UIDevice currentDevice] systemVersion] compare:@"6.0" options:NSNumericSearch] != NSOrderedAscending) 
        //running on ios 6.0 or higher
        [self.navigationController presentViewController:playerVc animated:YES completion:NULL];
     else 
        //running on iOS 5.x
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
        [self.navigationController presentModalViewController:playerVc animated:YES];
#endif
    
#else
    [self.navigationController presentModalViewController:playerVc animated:YES];
#endif


当单击 TableViewCell 时,它会打开并使用 RTSP 协议播放视频纵向模式 但我的要求是当单击 TableViewCell 时,它会以横向模式打开并播放视频,而无需移动旋转 请给出任何想法 提前感谢

【问题讨论】:

把这个链接代码***.com/questions/19095161/force-landscape-ios-7放到VSPlayerViewController类中 【参考方案1】:

VSPlayerViewController 类中,viewWillAppear/viewDidLoad 方法:

//rotate rect
self.view.transform = CGAffineTransformMakeRotation(M_PI_2); 

希望这会有所帮助。

【讨论】:

请在类中查看我的代码 VSplayerViewController 我没有放置 ViewDidLoad 方法请帮助我 尝试在 VSPlayerViewController.mm 文件的 ViewDidLoad 方法中添加该行代码。您添加的代码来自文件 Channel.mm k 我在实现通道中这样放置 - (void)viewDidLoad [super viewDidLoad]; self.view.transform = CGAffineTransformMakeRotation(M_PI_2) 但我得到的错误是在 Channel 类型的对象上找不到属性视图 我没有 VSPlayerViewController.mm 文件 然后在实现 VSPlayerViewController 类的地方编写此代码。在那个部分,会有 viewDidLoad 方法。

以上是关于如何在iphone中以横向模式播放视频的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Android WebView 中以横向全屏播放视频?

我的 iPhone 视频仅在纵向模式下播放

在 iOS 12 版全纵向应用中以横向播放 AVKit 全屏视频

在 iOS 7 横向模式下播放视频

使用标准 api 播放视频风景 Iphone sdk 3.2 4.0

当 iphone 处于睡眠模式/锁定时,如何使用视频播放?