- 浏览: 340028 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
leslie89757:
[img][img][img][img][img][img][ ...
CocoaPods 安装使用 -
hanmeizhi:
very useful to me. Thanks
Dismissing MPMoviePlayerViewController the right way -
luzj:
这个考虑不周全, 在iOS5的键盘高度就不是这个值了,这样写死 ...
UITextView: move view when keyboard appears -
xjg19870111:
不错。
objective-c NSString 常用操作 -
juedui0769:
现在已经不行了!
android源码下载
If you have used the MPMoviePlayerViewController to play videos in iOS, chances are you have gotten a little frustrated by its rigidness. A couple of issues I personally encountered were:
When presented modally, the view controller did not respect the modal transition style I had chosen for it.
When the video finished playing, the view controller dismissed itself automatically. I wanted it to remain visible until the user pressed the Done button.
A couple of hours of browsing for the solution to no avail, I decided to try out sort of a hack, which turned out to work great.
The trick is to remove the MPMoviePlayerViewController instance from the MPMoviePlayerPlaybackDidFinishNotification notification observers, and instead handle it yourself. Seems like this view controller listens to this notification and auto dismisses itself when it’s fired.
In my application, I present a thumbnail of the video. When touched, the video is played.
In the code above, an instance of MPMoviePlayerViewController is created, and then removed from the observers of the MPMoviePlayerDidFinishNotification immediately; in its place, the current class is added as an observer, with a selector named movieFinishedCallback: (described below).
In addition, the modalTransitionStyle property of the view controller is set. The documentation suggests you to use the presentMoviePlayerViewControllerAnimated method to present it, in order to use the standard movie player transition. But if you want to use different transition, you must use the regular presentModalViewController method.
Back to the observer notification. Now that the view controller is no longer an observer, it won’t dismiss itself, ever, even if the Done button is pressed. So you must implement the code to dismiss it.
In my case, my original problem was that I wanted the video to stay visible until the user deliberately pressed the Done button. In the code above, the notification’s “playback finished reason” is examined: if the video playback ended normally, then the notification is ignored; if the video playback ended for another reason (i.e. an error or the user exited), then the view controller is dismissed.
As an added bonus, by dismissing the view controller using the dismissModalViewControllerAnimated: method, the modal transition style set earlier is respected.
The code is kinda messy, but I hope you get the idea. Perhaps it would be desirable to encapsulate this code by extending the MPMoviePlayerViewController class.
When presented modally, the view controller did not respect the modal transition style I had chosen for it.
When the video finished playing, the view controller dismissed itself automatically. I wanted it to remain visible until the user pressed the Done button.
A couple of hours of browsing for the solution to no avail, I decided to try out sort of a hack, which turned out to work great.
The trick is to remove the MPMoviePlayerViewController instance from the MPMoviePlayerPlaybackDidFinishNotification notification observers, and instead handle it yourself. Seems like this view controller listens to this notification and auto dismisses itself when it’s fired.
In my application, I present a thumbnail of the video. When touched, the video is played.
- (void)playVideo:(NSString*)aVideoUrl { // Initialize the movie player view controller with a video URL string MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease]; // Remove the movie player view controller from the "playback did finish" notification observers [[NSNotificationCenter defaultCenter] removeObserver:playerVC name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer]; // Register this class as an observer instead [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer]; // Set the modal transition style of your choice playerVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // Present the movie player view controller [self presentModalViewController:playerVC animated:YES]; // Start playback [playerVC.moviePlayer prepareToPlay]; [playerVC.moviePlayer play]; }
In the code above, an instance of MPMoviePlayerViewController is created, and then removed from the observers of the MPMoviePlayerDidFinishNotification immediately; in its place, the current class is added as an observer, with a selector named movieFinishedCallback: (described below).
In addition, the modalTransitionStyle property of the view controller is set. The documentation suggests you to use the presentMoviePlayerViewControllerAnimated method to present it, in order to use the standard movie player transition. But if you want to use different transition, you must use the regular presentModalViewController method.
Back to the observer notification. Now that the view controller is no longer an observer, it won’t dismiss itself, ever, even if the Done button is pressed. So you must implement the code to dismiss it.
- (void)movieFinishedCallback:(NSNotification*)aNotification { // Obtain the reason why the movie playback finished NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey]; // Dismiss the view controller ONLY when the reason is not "playback ended" if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded) { MPMoviePlayerController *moviePlayer = [aNotification object]; // Remove this class from the observers [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; // Dismiss the view controller [self dismissModalViewControllerAnimated:YES]; } }
In my case, my original problem was that I wanted the video to stay visible until the user deliberately pressed the Done button. In the code above, the notification’s “playback finished reason” is examined: if the video playback ended normally, then the notification is ignored; if the video playback ended for another reason (i.e. an error or the user exited), then the view controller is dismissed.
As an added bonus, by dismissing the view controller using the dismissModalViewControllerAnimated: method, the modal transition style set earlier is respected.
The code is kinda messy, but I hope you get the idea. Perhaps it would be desirable to encapsulate this code by extending the MPMoviePlayerViewController class.
发表评论
-
IOS7.1 企业应用 证书无效 已解决
2014-05-10 10:53 773http://www.cocoachina.com/bbs/r ... -
xCode Find&Replace快捷键
2013-10-28 10:44 906As for Find & Replace, they ... -
iOS整合zxing需要注意的地方
2013-08-02 23:34 2104Well, at last I got it working. ... -
iOS 自定义Tabbar
2013-07-30 22:55 1189http://www.appcoda.com/ios-prog ... -
Apple Push Notification Service总结
2013-07-29 22:39 1112苹果推送通知服务使用总结 1. 在 Mac 上从 KeyCha ... -
iOS 消息推送原理及实现
2013-07-12 13:40 853链接: http://www.dapps.net/dev/ ... -
GIMP IMAGE MAP
2013-05-29 16:13 851使用GIMP 制作 IMAGE MAP 1. 选择图片,用G ... -
INSPIRATION
2013-05-27 18:21 811http://www.patternsofdesign.co. ... -
iOS 自定义控件系列
2013-05-27 17:09 1479iOS自定义控件 自定义UITableViewCell ht ... -
CocoaPods 使用教程
2013-05-27 14:49 767http://mobile.tutsplus.com/tuto ... -
IOS 开发之设置UIButton的title
2013-05-11 22:03 1205btn.frame = CGRectMake(x, y, wi ... -
REActivityViewController 使用 备忘
2013-04-22 21:38 1056REActivityViewController Out o ... -
VPS配置二级域名
2013-04-18 23:08 7851. 域名解析商配置泛解析 主机记录 * 记录类型 A 2. ... -
ios 开发NewsStand指南
2013-04-13 21:44 1322http://www.viggiosoft.com/blog/ ... -
Python Django mod_wsgi Windows 部署过程 备忘
2013-04-10 18:28 1585部署环境:Windows2003Server 1. 安装Ap ... -
网站迁移 备忘
2013-04-10 14:58 7491. 备份数据库。。。导出的格式和编码要注意 2. 完全导出网 ... -
Windows下命令行查看端口占用
2013-04-09 23:42 723在windows命令行窗口下执行: C:\>netst ... -
带预览功能又可分页的UIScrollView
2013-04-05 12:56 822带预览功能又可分页的UIScrollView http:// ... -
25 iOS App 性能优化
2013-04-05 10:51 693http://www.raywenderlich.com/ ... -
UIScrollView滚动, 中间显示整图, 前后露出部分图
2013-04-04 00:12 1200UIScrollView *scrollowView = [[ ...
相关推荐
Finishing with the right-hand-side content 144 Summary 149 [ iv ] Chapter 7: Of Course, You Can Build a Web App! 151 Alerts in our web app 152 Dismissing alerts 153 Customizing alerts 153 Waiting for ...
解压:DownloadDevTools.ir ... With the use of a simple as well as useful commands right on the differences that the user is interested as well dismissing of the ones that the user is not.
On the other hand, dismissing capability in favor of appearance oversimplifies the complex nature of professional success. While physical appearance might open doors, true career growth and ...
Fixed suggestion list dismissing unexpectedly when selecting an item after typing the global scope resolution operator (::). (case=21039) Find References | Find in Results works as expected. (case=...
A, being the case, you have no grounds for dismissing him. 如果情况如此的话,你没有理由解聘他。 His health being poor, he cannot attend the meeting. 由于他的健康状况不良,他不能参加会议。 独立主格...
- "__ is no reason for dismissing her." 这是一个主语从句,需要用"The fact that..."引导,答案是"C.The fact that she was a few minutes late"。 8. **日常对话与购物**: - "How much is this necklace?" ...
14. 题14的"The fact that ________ is no reason for dismissing her"中,"The fact"后接同位语从句,C "The fact that she was a few minutes late"是正确的。 15. 题15的"They came to the conclusion ________...
The GlowPadView library is basically Android is Lock Ring (way of screen-unlocking and alarm dismissing), but extended and targeted to Honeycomb and later versions of Android. I tried getting it to ...
4. 题目 "____ is no reason for dismissing her." 的正确答案是 C. The fact that she was a few minutes late。这里的"The fact"是主语,"that she was a few minutes late"是同位语从句,补充说明事实的具体内容...
4. 题目4 "______ is no reason for dismissing her." 选项C "The fact that she was a few minutes late" 为正确答案,因为"the fact"后面跟的是that引导的同位语从句,作为事实的具体内容。 5. 题目5 "______ Tom...
4. 下课(Dismissing the class):结束课程时,教师可以说"请交上练习册"(Hand in your workbooks, please)、"时间到了"(Time is up)或"下课了"(Class is over)等,同时道别,如"再见"(Goodbye)。...
- **并列句和条件状语从句**:在句子“Dismissing small talk as unimportant is easy, but we can't forget that deep relationships wouldn't even exist if it weren't for casual conversation.”中,了解如何...
11. 下课(Dismissing the class) 在英语课堂中,教师需要使用适当的语言来结束课程,例如:“That is all for today.”、“Class is over.”等。 英语课堂用语是英语教学中的重要组成部分,对英语教学的效果和...
Toast.makeText(MainActivity.this, "Mid pressed and dismissing...", Toast.LENGTH_SHORT).show(); menuOverlay.getButtonMenu().toggle();//切换,此时是关闭子菜单 break; case LEFT: Toast...
描述 ... 有时可能很难关闭键盘,因为您需要知道哪个视图是第一响应者。 IHKeyboardDismissing减轻了痛苦,并且会简单地遍历其子视图,并在找到它时解散第一个响应者 如何安装 将此添加到您的CocoaPods Podfile。...
8. ** dismissing the keyboard**: - 当用户点击屏幕其他区域或按下返回键时,需要隐藏键盘。这可以通过添加一个tap gesture recognizer到视图背景,或实现`textFieldShouldReturn(_ textField:)`代理方法来实现。...
Dismissing Dialogs Displaying an Icon Stacked Action Buttons Stacking Behavior Neutral Action Button Callbacks CheckBox Prompts List Dialogs Single Choice List Dialogs Coloring Radio Buttons Multi...
3. 恢复背景(Dismissing the Dimming Effect): 当PopupWindow消失时,我们需要恢复背景的原始状态。这可以通过监听PopupWindow的Dismiss事件来完成,当 PopupWindow被关闭时,移除那个半透明的背景视图。 4. ...
这个弹出框可能需要实现 dismissing 动画以及相应的事件处理。 5. **数据驱动**:如果切换栏与数据源关联,开发者需要维护一个数据模型,并在切换时更新列表内容或触发相关业务逻辑。 6. **KVO(Key-Value ...
同时,我们可以监听PopupWindow的 dismissing 事件,以便进行相应的处理: ```java popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { // 在这里...