iOS MediaPlayer使应用程序崩溃

时间:2013-08-01 21:21:43

标签: ios media-player

如果我从极简主义的UI实现开始,包括将单个UIButton(带有相应的IBOutlet)添加到默认情节提要板中的默认视图并向我的控制器类添加操作方法,那么一切正常(即我的操作)当我点击按钮时调用。

现在,如果我只是将MediaPlayer / MediaPlayer.h包含到我的视图控制器头文件中,就像那样:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface Playing_Video_FilesViewController : UIViewController

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
@property (nonatomic, strong) IBOutlet UIButton *playButton;

@end

并将MediaPlayer框架添加到项目中,它与臭名昭着的“这个类不是密钥值编码兼容的关键playButton”崩溃。

如果从项目中删除MediaPlayer框架引用,它将停止崩溃。如果我改为删除按钮但离开MediaPlayer框架,它也会停止崩溃。

我还应该做些什么来同时使用MediaPlayer和基本标准用户界面?

修改 我通过创建.xib文件而不是使用故事板来规避问题,就像在不使用故事板的VideoPlayer示例应用程序中完成它一样。相同的代码,但现在它可以工作。

1 个答案:

答案 0 :(得分:0)

每当我有一个不再正确连接的插座或动作时,我就会看到这一点。

1.) Open storyboard
2.) Select playButton
3.) Remove all outlets and actions from this item
4.) Remove plugs from your class that were previously attached (especially in dealloc)
5.) Create new outlet and control-drag from the storyboard to your class. Good to go.

- 有点矫枉过正,但每次都为我完成工作。