我在使用 AVPlayer 时遇到了一个奇怪的问题。我正在使用 AVplayer 播放在我的应用程序中下载的视频。下面的代码是我设置 AVPlayer 的方式。
var filePath = new NSString("file://" + filePathOnDisk);
var fileUrl = new NSUrl(filePath);
_asset = AVAsset.FromUrl(fileUrl);
_playerItem = new AVPlayerItem(_asset);
_player = new AVPlayer(_playerItem);
_playerStateObserver = _player.AddObserver("status", NSKeyValueObservingOptions.New, PlayerReadyObserver);
_playerLayer = AVPlayerLayer.FromPlayer(_player);
_playerLayer.Frame = Frame;
Layer.AddSublayer(_playerLayer);
当我像上面第 6 行那样添加观察者时,观察者工作正常并调用我分配给它的 Action。问题是当我尝试暂停 AVPlayer 时。它会导致 Mono 运行时崩溃,无法使用 C# 中的 try/catch 捕获。
我已经确认,如果我不添加观察者,我可以暂停 AVPlayer 而不会发生任何崩溃,但是我不知道如何在播放器准备好播放时进行监听。
添加一个观察者会返回一个 IDisposable,我也有一个引用。如果我在调用 Pause 之前处理该变量,则不会发生崩溃。谁能解释为什么会这样。以下是发生此崩溃时我得到的崩溃日志。
如有任何见解,我们将不胜感激。 谢谢。
下面的调用堆栈
2017-07-12 14:36:52.789 Educor.Mobile.Ios[8803:411224] critical: Stacktrace:
2017-07-12 14:36:52.789 Educor.Mobile.Ios[8803:411224] critical: at <unknown> <0xffffffff>
2017-07-12 14:36:52.790 Educor.Mobile.Ios[8803:411224] critical: at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) [0x0000a] in <58a9bd8a3cbb4d0092bc0a767ff66c0f>:0
2017-07-12 14:36:52.790 Educor.Mobile.Ios[8803:411224] critical: at AVFoundation.AVPlayer.Pause () [0x00003] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/build/ios/native/AVFoundation/AVPlayer.g.cs:196
2017-07-12 14:36:52.790 Educor.Mobile.Ios[8803:411224] critical: at Educor.Mobile.Ios.CustomViews.BindableViews.BindableNativeVideoPlayer.TogglePlayState () [0x0000d] in /Users/danemackier/MyFiles/Work/Clients/Educor/MoodleApp/MoodleSrc/Educor.Mobile.Ios/CustomViews/BindableViews/BindableNativeVideoPlayer.cs:71
2017-07-12 14:36:52.790 Educor.Mobile.Ios[8803:411224] critical: at Educor.Mobile.Ios.Views.NativeVideoPlayer.NativeVideoPlayerView.<HandlePlayPauseUi>b__8_0 () [0x00001] in /Users/danemackier/MyFiles/Work/Clients/Educor/MoodleApp/MoodleSrc/Educor.Mobile.Ios/Views/NativeVideoPlayer/NativeVideoPlayerView.cs:68
2017-07-12 14:36:52.790 Educor.Mobile.Ios[8803:411224] critical: at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/Foundation/NSAction.cs:163
2017-07-12 14:36:52.791 Educor.Mobile.Ios[8803:411224] critical: at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x0004f] in <2f4074c3120b4d80802e10af84b67d41>:0
2017-07-12 14:36:52.791 Educor.Mobile.Ios[8803:411224] critical: at <unknown> <0xffffffff>
2017-07-12 14:36:52.791 Educor.Mobile.Ios[8803:411224] critical: at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) [0x0005c] in <58a9bd8a3cbb4d0092bc0a767ff66c0f>:0
2017-07-12 14:36:52.791 Educor.Mobile.Ios[8803:411224] critical: at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/UIKit/UIApplication.cs:79
2017-07-12 14:36:52.791 Educor.Mobile.Ios[8803:411224] critical: at UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/UIKit/UIApplication.cs:63
2017-07-12 14:36:52.791 Educor.Mobile.Ios[8803:411224] critical: at Educor.Mobile.Ios.Application.Main (string[]) [0x00001] in /Users/danemackier/MyFiles/Work/Clients/Educor/MoodleApp/MoodleSrc/Educor.Mobile.Ios/Main.cs:12
2017-07-12 14:36:52.792 Educor.Mobile.Ios[8803:411224] critical: at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <075daed4d09344098906c84c2a5b9b38>:0
2017-07-12 14:36:52.792 Educor.Mobile.Ios[8803:411224] critical:
Native stacktrace:
2017-07-12 14:36:52.802 Educor.Mobile.Ios[8803:411224] critical: 0 libmonosgen-2.0.dylib 0x00000001054030f1 mono_handle_native_crash + 257
2017-07-12 14:36:52.802 Educor.Mobile.Ios[8803:411224] critical: 1 libmonosgen-2.0.dylib 0x000000010535e090 mono_sigsegv_signal_handler + 288
2017-07-12 14:36:52.802 Educor.Mobile.Ios[8803:411224] critical: 2 libsystem_platform.dylib 0x0000000109b3cbba _sigtramp + 26
2017-07-12 14:36:52.802 Educor.Mobile.Ios[8803:411224] critical: 3 libmonosgen-2.0.dylib 0x0000000105707428 mono_defaults + 0
2017-07-12 14:36:52.803 Educor.Mobile.Ios[8803:411224] critical: 4 AVFoundation 0x00000001025def4d -[AVPlayer willChangeValueForKey:] + 86
2017-07-12 14:36:52.803 Educor.Mobile.Ios[8803:411224] critical: 5 AVFoundation 0x00000001025e5615 -[AVPlayer setRate:withVolumeRampDuration:playImmediately:] + 90
2017-07-12 14:36:52.803 Educor.Mobile.Ios[8803:411224] critical: 6 AVFoundation 0x00000001025e598a -[AVPlayer setRate:] + 79
2017-07-12 14:36:52.803 Educor.Mobile.Ios[8803:411224] critical: 7 libxamarin-debug.dylib 0x0000000105853a59 xamarin_dyn_objc_msgSend + 217
2017-07-12 14:36:52.803 Educor.Mobile.Ios[8803:411224] critical: 8 ??? 0x000000011545587e 0x0 + 4651833470
2017-07-12 14:36:52.804 Educor.Mobile.Ios[8803:411224] critical: 9 ??? 0x000000011674d85e 0x0 + 4671723614
2017-07-12 14:36:52.804 Educor.Mobile.Ios[8803:411224] critical: 10 ??? 0x00000001147f5584 0x0 + 4638856580
2017-07-12 14:36:52.804 Educor.Mobile.Ios[8803:411224] critical: 11 libmonosgen-2.0.dylib 0x0000000105361045 mono_jit_runtime_invoke + 1301
2017-07-12 14:36:52.804 Educor.Mobile.Ios[8803:411224] critical: 12 libmonosgen-2.0.dylib 0x000000010553cbf8 do_runtime_invoke + 88
2017-07-12 14:36:52.804 Educor.Mobile.Ios[8803:411224] critical: 13 libmonosgen-2.0.dylib 0x000000010553cb70 mono_runtime_invoke + 208
2017-07-12 14:36:52.805 Educor.Mobile.Ios[8803:411224] critical: 14 libxamarin-debug.dylib 0x000000010584a2a5 xamarin_invoke_trampoline + 5589
2017-07-12 14:36:52.805 Educor.Mobile.Ios[8803:411224] critical: 15 libxamarin-debug.dylib 0x000000010585250d xamarin_arch_trampoline + 189
2017-07-12 14:36:52.805 Educor.Mobile.Ios[8803:411224] critical: 16 libxamarin-debug.dylib 0x00000001058538d1 xamarin_x86_64_common_trampoline + 110
2017-07-12 14:36:52.805 Educor.Mobile.Ios[8803:411224] critical: 17 Foundation 0x000000010293fe9e __NSThreadPerformPerform + 326
2017-07-12 14:36:52.805 Educor.Mobile.Ios[8803:411224] critical: 18 CoreFoundation 0x0000000104ef9761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
2017-07-12 14:36:52.805 Educor.Mobile.Ios[8803:411224] critical: 19 CoreFoundation 0x0000000104ede98c __CFRunLoopDoSources0 + 556
2017-07-12 14:36:52.806 Educor.Mobile.Ios[8803:411224] critical: 20 CoreFoundation 0x0000000104edde76 __CFRunLoopRun + 918
2017-07-12 14:36:52.806 Educor.Mobile.Ios[8803:411224] critical: 21 CoreFoundation 0x0000000104edd884 CFRunLoopRunSpecific + 420
2017-07-12 14:36:52.806 Educor.Mobile.Ios[8803:411224] critical: 22 GraphicsServices 0x0000000106949a6f GSEventRunModal + 161
2017-07-12 14:36:52.806 Educor.Mobile.Ios[8803:411224] critical: 23 UIKit 0x0000000100d21c68 UIApplicationMain + 159
2017-07-12 14:36:52.806 Educor.Mobile.Ios[8803:411224] critical: 24 ??? 0x0000000114d4a37c 0x0 + 4644447100
2017-07-12 14:36:52.806 Educor.Mobile.Ios[8803:411224] critical: 25 ??? 0x0000000114d49fbd 0x0 + 4644446141
2017-07-12 14:36:52.806 Educor.Mobile.Ios[8803:411224] critical:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
最佳答案
您在函数调用中跳过了 observer。
代替
_playerStateObserver = _player.AddObserver("status", NSKeyValueObservingOptions.New, PlayerReadyObserver);
尝试
_playerStateObserver = _player.AddObserver(yourObserver, "status", NSKeyValueObservingOptions.New, nil);
关于ios - 添加观察者时 AVPlayer 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45058225/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
当谈到运行时自省(introspection)和动态代码生成时,我认为ruby没有任何竞争对手,可能除了一些lisp方言。前几天,我正在做一些代码练习来探索ruby的动态功能,我开始想知道如何向现有对象添加方法。以下是我能想到的3种方法:obj=Object.new#addamethoddirectlydefobj.new_method...end#addamethodindirectlywiththesingletonclassclass这只是冰山一角,因为我还没有探索instance_eval、module_eval和define_method的各种组合。是否有在线/离线资
我注意到类定义,如果我打开classMyClass,并在不覆盖的情况下添加一些东西我仍然得到了之前定义的原始方法。添加的新语句扩充了现有语句。但是对于方法定义,我仍然想要与类定义相同的行为,但是当我打开defmy_method时似乎,def中的现有语句和end被覆盖了,我需要重写一遍。那么有什么方法可以使方法定义的行为与定义相同,类似于super,但不一定是子类? 最佳答案 我想您正在寻找alias_method:classAalias_method:old_func,:funcdeffuncold_func#similartoca
我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司