webview - Running Youtube embedded player inside (cocoa) screensaver - how to block/trap fake user events? -
the youtube player seems send fake user input events in order prevent screensaver starting (i'm on osx/safari same thing happens in windows). happens both embedded players , 1 on yt site. i'm guessing design screensaver doesn't annoy while trying watch video.
however, i'm trying play youtube video within screensaver, trap , ignore or turn off these events. screensaver works great 6-8 seconds when exits gracefully if user moved mouse. think under windows catch , ignore it, i'm writing osx, can't seem trap code because never reaches code - handled screensaverengine app. mac screensavers plugins app, can't override main event loop (which calls nsapplication::sendevent). first hear event in applicationshouldterminate() delegate. can request app terminate later, postpones shutdown 1 second. stack trace below - can make out mouseexit apple event being sent.
i've looked , looked, , can't find way disable or catch these player events either in cocoa or in javascript. actual video loaded webview , runs using youtube javascript api, below stripped down test code produces same results. same results without running code doing following:
(1) play video in youtube (doesn't matter if embedded or not) (2) manually start screensaver via hot corner or whatever (3) wait few seconds
i assumed bug in code long time, because i'm new objective-c , javascript think it's design because above steps reproduce problem without using code @ all.
screensaver test code ----- .h file
#import <webkit/webkit.h> #import <screensaver/screensaver.h> @interface yttestview : screensaverview { webview * webview; } @end screensaver test code ----- .m file - think of parameters superfluous example, adapted excellent example alastair tse (https://github.com/liquidx/webviewscreensaver)
#import "yttestview.h" @implementation yttestview - (id)initwithframe:(nsrect)frame ispreview:(bool)ispreview { self = [super initwithframe:frame ispreview:ispreview]; if (self) { [self setanimationtimeinterval:1/30.0]; } return self; } - (void)startanimation { [super startanimation]; webview = [[webview alloc] initwithframe:[self bounds]]; [webview setframeloaddelegate:self]; [webview setshouldupdatewhileoffscreen:yes]; [webview setpolicydelegate:self]; [webview setuidelegate:self]; [webview seteditingdelegate:self]; [webview setautoresizingmask:nsviewwidthsizable|nsviewheightsizable]; [webview setautoresizessubviews:yes]; [webview setdrawsbackground:no]; [webview setmaintainsbackforwardlist:no]; [self addsubview:webview]; nsstring * url= @"http://www.youtube.com/embed/nlet--l6fno?autoplay=1"; [webview setmainframeurl:url]; } - (void)stopanimation { [super stopanimation]; } - (void)drawrect:(nsrect)rect { [super drawrect:rect]; } - (void)animateoneframe { return; } - (bool)hasconfiguresheet { return no; } - (nswindow*)configuresheet { return nil; } @end --------stack trace in applicationshouldterminate() - fyi
2013-05-20 23:41:20.558 screensaverengine[2143:c07] event: nsevent: type=kitdefined loc=(0,800) time=21467.6 flags=0 win=0x0 winnum=0 ctxt=0x0 subtype=1 data1=619 data2=0 2013-05-20 23:41:20.558 screensaverengine[2143:c07] window classname: (null) 2013-05-20 23:41:20.559 screensaverengine[2143:c07] event: type=13 2013-05-20 23:41:20.561 screensaverengine[2143:c07] 0: 0 ytss 0x0000000106167327 -[ytssview(nsapplicationdelegate) applicationshouldterminate:] + 343 2013-05-20 23:41:20.562 screensaverengine[2143:c07] 1: 1 appkit 0x00007fff85623e6f -[nsapplication _doccontroller:shouldterminate:] + 75 2013-05-20 23:41:20.562 screensaverengine[2143:c07] 2: 2 appkit 0x00007fff85623d7e __91-[nsdocumentcontroller(nsinternal) _closealldocumentswithdelegate:shouldterminateselector:]_block_invoke_0 + 159 2013-05-20 23:41:20.562 screensaverengine[2143:c07] 3: 3 appkit 0x00007fff85623c1a -[nsdocumentcontroller(nsinternal) _closealldocumentswithdelegate:shouldterminateselector:] + 1557 2013-05-20 23:41:20.563 screensaverengine[2143:c07] 4: 4 appkit 0x00007fff856235de -[nsdocumentcontroller(nsinternal) __closealldocumentswithdelegate:shouldterminateselector:] + 265 2013-05-20 23:41:20.563 screensaverengine[2143:c07] 5: 5 appkit 0x00007fff856234af -[nsapplication _shouldterminate] + 772 2013-05-20 23:41:20.563 screensaverengine[2143:c07] 6: 6 appkit 0x00007fff8565127f -[nsapplication(nsappleeventhandling) _handleaequit] + 403 2013-05-20 23:41:20.566 screensaverengine[2143:c07] 7: 7 appkit 0x00007fff854001b1 -[nsapplication(nsappleeventhandling) _handlecoreevent:withreplyevent:] + 660 2013-05-20 23:41:20.567 screensaverengine[2143:c07] 8: 8 foundation 0x00007fff8ea2370b -[nsappleeventmanager dispatchrawappleevent:withrawreply:handlerrefcon:] + 308 2013-05-20 23:41:20.567 screensaverengine[2143:c07] 9: 9 foundation 0x00007fff8ea2356d _nsappleeventmanagergenerichandler + 106 2013-05-20 23:41:20.567 screensaverengine[2143:c07] 10: 10 ae 0x00007fff906fa078 _z20aedispatchappleeventpk6aedescps_jph + 307 2013-05-20 23:41:20.567 screensaverengine[2143:c07] 11: 11 ae 0x00007fff906f9ed9 zl25dispatcheventandsendreplypk6aedescps + 37 2013-05-20 23:41:20.569 screensaverengine[2143:c07] 12: 12 ae 0x00007fff906f9d99 aeprocessappleevent + 318 2013-05-20 23:41:20.570 screensaverengine[2143:c07] 13: 13 hitoolbox 0x00007fff8d599709 aeprocessappleevent + 100 2013-05-20 23:41:20.570 screensaverengine[2143:c07] 14: 14 appkit 0x00007fff853fc866 _dpsnextevent + 1456 2013-05-20 23:41:20.570 screensaverengine[2143:c07] 15: 15 appkit 0x00007fff853fbe22 -[nsapplication nexteventmatchingmask:untildate:inmode:dequeue:] + 128 2013-05-20 23:41:20.570 screensaverengine[2143:c07] 16: 16 screensaverengine 0x0000000104b6e747 -[screensaverapplication nexteventmatchingmask:untildate:inmode:dequeue:] + 49 2013-05-20 23:41:20.571 screensaverengine[2143:c07] 17: 17 appkit 0x00007fff853f31d3 -[nsapplication run] + 517 2013-05-20 23:41:20.571 screensaverengine[2143:c07] 18: 18 screensaverengine 0x0000000104b6e5a3 main + 551 2013-05-20 23:41:20.571 screensaverengine[2143:c07] 19: 19 libdyld.dylib 0x00007fff907b47e1 start + 0 2013-05-20 23:41:20.571 screensaverengine[2143:c07] 20: 20 ??? 0x0000000000000001 0x0 + 1
Comments
Post a Comment