欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

视频播放

程序员文章站 2024-01-16 20:54:04
...
model块
//
//  JingDongModel.h
//  京东视频
//
//  Created by 岳飞洋(关机) on 2018/11/21.
//  Copyright © 2018 岳飞洋. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface JingDongModel : NSObject
@property(nonatomic , strong)NSArray *imageArr; // 图片数组
@property(nonatomic , strong)NSArray *labelArr; // 主标题数组
@property(nonatomic , strong)NSArray *priceArr; // 价格数组
@property(nonatomic , strong)NSArray *similarArr; // 相似数组
@property(nonatomic , strong)NSArray *memberArr; // 会员数组

@end

NS_ASSUME_NONNULL_END
//
//  JingDongModel.m
//  京东视频
//
//  Created by 岳飞洋(关机) on 2018/11/21.
//  Copyright © 2018 岳飞洋. All rights reserved.
//

#import "JingDongModel.h"

@implementation JingDongModel
// 图片数组
-(NSArray *)imageArr{
    
    _imageArr = @[@"123",@"234",@"345",@"456"];
    return _imageArr;
}
// 主标题数组
-(NSArray *)labelArr{
    
    _labelArr = @[@"京东物流 英皇保罗钱包男长款真皮头层牛皮男士钱包...",@"CK钱包男真皮士青年长款牛皮手拿包休闲拉链手机包...",@"京东超市 士力架花生夹心巧乐兹(共享装)糖果巧克力...",@"京东超市 士力架花生夹心巧乐兹(共享装)糖果巧克力..."];
    return _labelArr;
    
}
// 价钱数组
-(NSArray *)priceArr{
    
    _priceArr = @[@"$168.00 满减",@"$268.00 券",@"$120.00 满减",@"$68.00 券"];
    return _priceArr;
    
}
// 相似数组
-(NSArray *)similarArr{
    
    _similarArr = @[@"看相似",@"看相似",@"看相似",@"看相似"];
    return _similarArr;
}
// 会员数组
-(NSArray *)memberArr{
    
    _memberArr = @[@"$159.00 PLUS",@"您的浏览足迹",@"$159.00 PLUS",@"$159.00 PLUS"];
    return _memberArr;
    
}

@end
//
//  JDCollectionViewCell.h
//  京东视频
//
//  Created by 岳飞洋(关机) on 2018/11/21.
//  Copyright © 2018 岳飞洋. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface JDCollectionViewCell : UICollectionViewCell

@property(nonatomic , strong)UIImageView *imageView;
@property(nonatomic , strong)UILabel *ZhuLabel;
@property(nonatomic , strong)UILabel *priceLabel;
@property(nonatomic , strong)UIButton *similarBtn;
@property(nonatomic , strong)UILabel *memberLabel;

@end

NS_ASSUME_NONNULL_END

//
//  JDCollectionViewCell.m
//  京东视频
//
//  Created by 岳飞洋(关机) on 2018/11/21.
//  Copyright © 2018 岳飞洋. All rights reserved.
//

#import "JDCollectionViewCell.h"

@implementation JDCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame{
    
    if(self == [super initWithFrame:frame]){
        
        [self addSubview:self.imageView];
        [self addSubview:self.ZhuLabel];
        [self addSubview:self.similarBtn];
        [self addSubview:self.priceLabel];
        [self addSubview:self.memberLabel];
    }
    
    
    return self;
}
-(UIImageView *)imageView{
    
    if(!_imageView){
        
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 5, 200, 200)];
        
    }
    
    return _imageView;
    
}
-(UILabel *)ZhuLabel{
    
    if(!_ZhuLabel){
        
        
        _ZhuLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 220, 200, 50)];
        _ZhuLabel.textColor = [UIColor blackColor];
        _ZhuLabel.font = [UIFont systemFontOfSize:16];
        _ZhuLabel.numberOfLines = 0;
    }
    return _ZhuLabel;
}
-(UILabel *)priceLabel{
    
    if(!_priceLabel){
        
        _priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 260, 100, 40)];
        _priceLabel.textColor = [UIColor redColor];
        _priceLabel.font = [UIFont systemFontOfSize:16];
        
    }
    
    return _priceLabel;
}



-(UIButton *)similarBtn{
    
    if(!_similarBtn){
        
        _similarBtn = [[UIButton alloc]initWithFrame:CGRectMake(140, 270, 50, 30)];
        _similarBtn.layer.masksToBounds = YES;
        _similarBtn.layer.cornerRadius = 15;
        [self.similarBtn setImage:[UIImage imageNamed:@"btn"] forState:UIControlStateNormal];
        
    }
    
    return _similarBtn;
}
-(UILabel *)memberLabel{
    
    if(!_memberLabel){
        
        _memberLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 300, 100, 20)];
        _memberLabel.font = [UIFont systemFontOfSize:14];
        _memberLabel.textColor = [UIColor blackColor];
        
        
    }
    return _memberLabel;
    
    
}




@end
//
//  SYViewController.m
//  京东视频
//
//  Created by 岳飞洋(关机) on 2018/11/21.
//  Copyright © 2018 岳飞洋. All rights reserved.
//

#import "SYViewController.h"
#import "QBViewController.h"
#import "FCJXViewController.h"

#import "SCNavTabBarController.h"
@interface SYViewController ()
@end

@implementation SYViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    QBViewController *qb = [QBViewController new];
    qb.title = @"全部";
    
    
    FCJXViewController *fcjx = [FCJXViewController new];
    fcjx.title = @"返厂精选";
    
    // 创建SCNavTabBar
    SCNavTabBarController *scNav = [SCNavTabBarController new];
    //    scNav.d
    scNav.subViewControllers = @[qb , fcjx];
    
    // 设置背景颜色
    [scNav setNavTabBarColor:[UIColor whiteColor]];
    // 执行管理
    [scNav addParentController:self];
    
    
    
    // 创建导航栏颜色
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    // 创建导航栏
    // 创建一个uiview
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 35, 35)];
    // 创建一个uibutton
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(5, 0, 25, 25)];
    [btn setImage:[UIImage imageNamed:@"111"] forState:UIControlStateNormal];
    // 添加到view中
    [view addSubview:btn];
    // 创建一个label
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(2, 27, 35, 10)];
    // 设置文字
    label.text = @"扫啊扫";
    // 设置文字颜色
    label.textColor = [UIColor whiteColor];
    // 设置字号大小
    label.font = [UIFont systemFontOfSize:10];
    // 添加到view中
    [view addSubview:label];
    // 添加到导航视图中
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:view];
    
    // 创建搜索框
    UISearchBar *sear = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 180, 40)];
    // 设置文10
    sear.placeholder = @" 居家好物每满400减50元";
    // 设置按钮图片
    UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(280, 18, 20, 20)];
    // 加载图片
    [btn1 setImage:[UIImage imageNamed:@"222"] forState:UIControlStateNormal];
    // 添加到sear中
    [sear addSubview:btn1];
    // 添加到视图中
    self.navigationItem.titleView = sear;
    
    // 创建一个uiview
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 15, 35, 35)];
    // 创建一个uibutton
    UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(3, 5, 25, 25)];
    [btn2 setImage:[UIImage imageNamed:@"333"] forState:UIControlStateNormal];
    // 添加到view1中
    [view1 addSubview:btn2];
    
    
    // 创建一个uiview
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(10, 15, 35, 35)];
    // 创建一个uibutton
    UIButton *btn3 = [[UIButton alloc]initWithFrame:CGRectMake(3, 5, 25, 25)];
    [btn3 setImage:[UIImage imageNamed:@"444"] forState:UIControlStateNormal];
    // 添加到view1中
    [view2 addSubview:btn3];
    // 设置一个label
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 29, 35, 9)];
    // 设置文字
    label2.text = @"消息";
    // 设置文字颜色
    label2.textColor = [UIColor whiteColor];
    // 设置文字大小
    label2.font = [UIFont systemFontOfSize:10];
    // 添加到view1中
    [view2 addSubview:label2];
    // 添加到视图中
    UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithCustomView:view1];
    UIBarButtonItem *right1 = [[UIBarButtonItem alloc]initWithCustomView:view2];
    self.navigationItem.rightBarButtonItems = @[right1 , right];
    
    
}
@end
//
分段控制器
//  QBViewController.m
//  京东视频
//
//  Created by 岳飞洋(关机) on 2018/11/21.
//  Copyright © 2018 岳飞洋. All rights reserved.
//

#import "QBViewController.h"
#import "JingDongModel.h"
#import "JDCollectionViewCell.h"
#import "FLViewController.h"
@interface QBViewController ()<UICollectionViewDelegate , UICollectionViewDataSource>
{
    UICollectionViewFlowLayout *flowLayout;
    UICollectionView *cv;
}
@end
static NSString *oj = @"cell";
@implementation QBViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    
    // 创建流水布局
    flowLayout = [[UICollectionViewFlowLayout alloc]init];
    // 设置网格大小
    flowLayout.itemSize = CGSizeMake((self.view.frame.size.width-10)/2, 320);
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 0;
    // 设置最小列间距
    flowLayout.minimumInteritemSpacing = 0;
    // 创建网格
    cv = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flowLayout];
    // 设置代理
    cv.delegate = self;
    cv.dataSource = self;
    // 设置网格背景颜色
    cv.backgroundColor = [UIColor whiteColor];
    // 注册cell
    [cv registerClass:[JDCollectionViewCell class] forCellWithReuseIdentifier:oj];
    
    [self.view addSubview:cv];
    
    
    
    
}
// 设置网格个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}
-(JDCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    JDCollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:oj forIndexPath:indexPath];
    
    JingDongModel *model = [JingDongModel new];
    cell.imageView.image = [UIImage imageNamed:model.imageArr[indexPath.row]];
    cell.ZhuLabel.text = model.labelArr[indexPath.row];
    cell.priceLabel.text = model.priceArr[indexPath.row];
    cell.memberLabel.text = model.memberArr[indexPath.row];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    self.hidesBottomBarWhenPushed = YES;
    FLViewController *fl = [FLViewController new];
    [self.navigationController pushViewController:fl animated:YES];
    self.hidesBottomBarWhenPushed = NO;
    
}
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
}

@end
//
视频播放
//  FLViewController.m
//  京东视频
//
//  Created by 岳飞洋(关机) on 2018/11/21.
//  Copyright © 2018 岳飞洋. All rights reserved.
//

#import "FLViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
@interface FLViewController ()

@end

@implementation FLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    
    UIImageView *imgV = [[UIImageView alloc]initWithFrame:self.view.frame];
    imgV.image = [UIImage imageNamed:@"tu"];
    [self.view addSubview:imgV];
    
//    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
//    [btn setImage:[UIImage imageNamed:@"fan"] forState:UIControlStateNormal];
//    btn.layer.masksToBounds = YES;
//    btn.layer.cornerRadius = 20;
//    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:btn];
//
    
    UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(155, 350, 100, 40)];
    [btn1 setImage:[UIImage imageNamed:@"bo"] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(playBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    
    
    
}
-(void)btnClick{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)playBtn{
    
    
    // 本地资源文件
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"111.mp4" ofType:nil];
    
    // 创建视频播放控制器
    AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc]init];
    
    // 设置视频播放器
    playerViewController.player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:filePath]];
    
    [self presentViewController:playerViewController animated:YES completion:nil];
    
    // 4. 开始播放 : 默认不会自动播放
    [playerViewController.player play];
    
    
    
    
}

@end

相关标签: 视频播放