ios开发怎么调用系统播放器播放网络视频

2025-02-22 21:59:36
推荐回答(3个)
回答1:

这个比较难,一句两句说不清的。

回答2:

我也想知道具体的答案,希望给出详细代码

回答3:

这是源码
1 //
2 // YYViewController.m
3 // 01-文顶顶客户端
4 //
5 // Created by apple on 14-6-29.
6 // Copyright (c) 2014年 itcase. All rights reserved.
7 //
8
9 #import "YYViewController.h"
10 #import "MBProgressHUD+MJ.h"
11 #import "YYviodesModel.h"
12 #import "UIImageView+WebCache.h"
13 #import "YYCell.h"
14 #import
15
16 @interface YYViewController ()
17 @property(nonatomic,strong)NSArray *videos;
18
19 @end
20
21 @implementation YYViewController
22
23 - (void)viewDidLoad
24 {
25 [super viewDidLoad];
26 //去掉下划线
27 self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
28
29 [MBProgressHUD showMessage:@"正在努力加载中"];
30
31 //创建路径
32
33 NSString *urlStr=@"http://192.168.1.53:8080/MJServer/video";
34 NSURL *url=[NSURL URLWithString:urlStr];
35
36 //创建请求
37 NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];//默认为get请求
38 //设置最大的网络等待时间
39 request.timeoutInterval=20.0;
40
41 //获取主队列
42 NSOperationQueue *queue=[NSOperationQueue mainQueue];
43 //发起请求
44 [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
45 //隐藏HUD
46 [MBProgressHUD hideHUD];
47 if (data) {//如果请求成功,拿到服务器返回的数据
48 //解析拿到的数据(JSON方式)
49 NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
50 // NSArray *array=dict[@"video"];
51 NSArray *array=dict[@"videos"];
52
53 NSMutableArray *videos=[NSMutableArray array];
54 for (NSDictionary *dict in array) {
55 YYviodesModel *model=[YYviodesModel viodesModelWithDict:dict];
56 [videos addObject:model];
57 }
58 self.videos=videos;
59
60 //刷新表格
61 [self.tableView reloadData];
62
63 }else//如果请求失败,没有拿到数据
64 {
65 [MBProgressHUD showError:@"网络繁忙,等稍后再试!"];
66 }
67
68 }];
69 }
70
71 #pragma mark-数据源方法
72 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
73 {
74 return 1;
75 }
76 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
77 {
78 return self.videos.count;
79 }
80 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
81 {
82 static NSString *ID=@"ID";
83 YYCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
84 if (cell==nil) {
85 cell=[[YYCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
86 }
87
88 //获取数据模型
89 YYviodesModel *model=self.videos[indexPath.row];
90 cell.textLabel.text=model.name;
91 NSString *length=[NSString stringWithFormat:@"时长%d分钟",model.length];
92 cell.detailTextLabel.text=length;
93
94 // video.image == resources/images/minion_01.png
95 NSString *imageUrl = [NSString stringWithFormat:@"http://192.168.1.53:8080/MJServer/%@", model.image];
96
97 //这里使用了第三方框架
98 [cell.imageView setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
99
100 return cell;
101 }
102
103 //设置cell的行高
104 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
105 {
106 return 70;
107 }
108
109 //播放视频
110 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
111 {
112 //取出数据模型
113 YYviodesModel *model=self.videos[indexPath.row];
114
115 //创建视屏播放器
116 // MPMoviePlayerController 可以随意控制播放器的尺寸
117 //MPMoviePlayerViewController只能全屏播放
118
119 NSString *url = [NSString stringWithFormat:@"http://192.168.1.53:8080/MJServer/%@", model.url];
120 NSURL *videoUrl=[NSURL URLWithString:url];
121 MPMoviePlayerViewController *movieVc=[[MPMoviePlayerViewController alloc]initWithContentURL:videoUrl];
122 //弹出播放器
123 [self presentMoviePlayerViewControllerAnimated:movieVc];
124
125 }
126 @end