QT Capture Widget

Discussion in 'Mac Programming' started by I'm a Mac, Apr 10, 2008.

  1. macrumors 6502

    Joined:
    Nov 5, 2007
    #1
    I created a widget based off of the QT capture widget that I found on Apple's Developer Website, but whenever I deploy the widget to dashboard, and even after I close it, my iSight thinks it's still in use, and I must restart or sleep and wake my computer. Any ideas?
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    How does this widget work? I'm not familiar with it, could you post a link?

    What you probably need to do is make sure the video stream is closed when the widget is done working. I'm not sure if the widget gets a notification when it's closing or being hidden, but if so that'd be a good place to do it.

    Edit: found the link.

    Looking at the code for qtcapture.js, I see this:

    Code:
    if (window.widget) {
        widget.onremove = remove;
        widget.onhide = hide;
        widget.onshow = show;
        widget.onsync = sync;
    }
    So it looks like it's setup to automatically handle stopping the capture when the widget is hidden or removed. I'd double-check and make sure those functions are getting called.
     
  3. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #3
    I see the code there in .js file but how to I check if its being called?

    I have no coding knowledge, sorry.

    Also, if I have a glass button on my widget, how do I get it to move every time it's clicked?
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    I don't know if widgets will acts like "any other javascript", but if so you should be able to put an alert("Message"); in those four functions and see if the alert shows up.

    -Lee
     
  5. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #5
    Arghh... I still have to restart my computer after launching the widget. I wish I could send it to someone who actually HAS coding knowledge. :eek:
     
  6. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    Are you sure you're closing the widget? Even when I used the sample code, it didn't "let go" of the camera until I actually closed it. Leaving the dashboard, etc. didn't do it. i had to click the "+" on the bottom left of the dashboard, then click the "X" at the upper left of the widget.

    -Lee
     
  7. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #7
    I think you need to look at the code for QTCapturePlugin. Looks like the video input device isn't removed from the capture session. I've had a quick go at fixing it but no success yet.

    b e n
     
  8. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #8
    Yes, I am actually closing the widget. But somethings weird because in the QTCapture widget files, the widgetproj file is different from the actual widget, and i had to use the widgetproj file.
     
  9. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #9
    Well I managed to fix it so the iSight turns off when you hide the widget. I put a call to captureDelete in the stopRecording method of the plugin, and a captureInit in startRecording. It was a quick hack though.
    b e n
     
  10. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #10

    How do I do that?
     
  11. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #11
    hi i'm a mac

    I changed these methods in MyCaptureView.m like this:-

    Code:
    /* start capturing */
    -(void)startCapture
    {
    	if ([mCaptureSession isRunning] == NO)
    	{
    		[self captureInit] ;
    		if (([[mCaptureVideoDeviceInput device] isOpen] == YES) && ([[mCaptureAudioDeviceInput device] isOpen] == YES))
    		{
    			[mCaptureSession startRunning];
    		}
    	}
    
    }
    
    /* stop capturing */
    -(void)stopCapture
    {
    	if ([mCaptureSession isRunning] == YES)
    	{
    		[self captureDelete] ;
    		[mCaptureSession stopRunning];
    	}
    
    }
    
    Like I said, it was a quick hack just to force the input devices to be released. You might want to look through captureDelete and captureInit to see what you need for your own, better solution.

    good luck!

    b e n
     

Share This Page