Movies and Menus
Pages: 1, 2, 3
Implementing These Methods
With the Interface reconfigured to our needs, we return to Project Builder to implement these methods. If you've scanned over the NSMovieView documentation, you probably have a good idea of what's going to happen next. The first method we will implement is -playMovie:, and this is done with just one line of code:
- (IBAction)playMovie:(id)sender
{
[movieView start:self];
}
Here we used the NSMovieView method start: to start playing the movie. The argument to the method is the message sender, which we set as self here. The method -pauseMovie: is nearly the same:
- (IBAction)pauseMovie:(id)sender
{
[movieView stop:self];
}
You see here that all we are doing is invoking the stop method of NSMovieView; easy enough. The third method, -toggleLoopMode:, is slightly more complicated.
The idea is that we want to allow the user to toggle between not looping through the movie and looping through it. When the movie is in loop mode, there will be a check next to the Loop menu item. A check indicates that the menu item is in its on state; no check indicates that the menu item is in its off state. One can set and determine the state of a menu item using NSMenuItem's -setState and -state: methods, respectively.
A QuickTime movie has three play modes with respect to looping. The first mode is normal playback mode, the second is looping playback mode, and the third is loop back-and-forth playback mode; we will only toggle between the first two.
The idea of -toggleLoopPlayback is to check the state of the menu item and change the looping mode accordingly, in addition to changing the state to reflect the changed looping mode. Let's lay it out and take a look:
- (IBAction)toggleLoopMode:(id)sender
{
if ( [sender state] == NSOnState ) {
[sender setState:NSOffState];
[movieView setLoopMode:NSQTMovieNormalPlayback];
} else {
[sender setState:NSOnState];
[movieView setLoopMode:NSQTMovieLoopingPlayback];
}
}
We checked to see whether or not the menu item was in its on state, and if so, we set it to the off state and set the playback mode to normal. If the menu item's state was off, then we changed it to on and set the playback mode to looping playback. NSQTMovieNormalPlayback and NSQTMovieLoopingPlayback are just constants used to represent these two modes.
|
Also in Programming with Cocoa |
Now compile and run you application and play around with it. With a little bit of exploration, it shouldn't be long before you notice that Loop in the dock menu acts a little screwy. If you look at Project Builder's runtime error messages, you'll notice that you get something telling you that NSApplication doesn't respond to state messages.
The source of these error messages and the undesirable behavior in the dock menu has to do with the nature of the dock menu itself. The Dock is a separate application that displays dock menus. Communication happens between the dock and your application to send messages as a result of selecting custom dock menu items, such as Loop. Unfortunately, what this means for us is that when we expect the sender argument variable to be assigned to the menu item itself, which does indeed respond to state, it is really assigned to the application instance, since that is the object communicating with the Dock and the dock menu.
The moral of the story is that we can't rely on the otherwise convenient sender argument variable being the menu item when working with dock menus. A solution to this problem is to create an outlet in Controller that is connected to the menu item, and then we can communicate directly with the menu item, rather than relying on the sender argument. I'll leave this for you to work out, and you can see it in my project available for download here.
With that, we've come to the end of today's column. I hope you enjoyed it and have found something useful in it. I mentioned earlier the issue of movies being resized to the NSMovieView size, and I would like to make a request to address this issue. See you next time!
Return to the Mac DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 36 of 36.
-
Dock Menu
2004-04-30 16:18:02 metacell [Reply | View]
It's been a while for some, but I just found this series. Just to let you know, under OS 10.3, the Loop Toggle menu works fine on the dock, no added code is needed to make it work (the checkmark also works fine.)
I imagine by now that the dock is completely cocoa-ized, and now apparently supports states.
-
Movie Dimensions...
2003-01-28 15:38:36 below [Reply | View]
OK,
here is the requested source code to find out the Dimensions of a movie. This is pure 'C', not Objective-C, and it uses Carbon, as this sort of functionality is not yet present in Cocoa.
I stripped it of all comments for size, but if you have any questions mail me: below-at-mac-dot-com.
This is based on Apple sample code, hidden well somewhere in the Dev Info...
Alex
code starts here ----->
#include <Carbon/Carbon.h>
#include <QuickTime/QuickTime.h>
#include "QTUtils.h"
Boolean QTUtils_MovieSize (Movie theMovie, Rect * movieRect)
{
OSErr myErr = paramErr;
short trackCount, index;
if (theMovie == NULL)
return(false);
trackCount = GetMovieTrackCount(theMovie);
for(index = 1; index <= trackCount; index++)
{
Track aTrack = NULL;
Media aMedia = NULL;
OSType aMediaType;
aTrack = GetMovieIndTrack(theMovie, index);
aMedia = GetTrackMedia(aTrack);
myErr = GetMoviesError();
if(myErr != noErr)
{
printf("Problems with getting trackmedia = %d\n", myErr);
return false;
}
GetMediaHandlerDescription(aMedia, &aMediaType, 0, 0);
if(aMediaType == VideoMediaType) // We just want to check the video media samples.
{
SampleDescriptionHandle anImageDesc = NULL;
anImageDesc = (SampleDescriptionHandle)NewHandle(sizeof(SampleDescription));
GetMediaSampleDescription(aMedia, 1, anImageDesc);
myErr = GetMoviesError();
if(myErr != noErr)
{
DisposeHandle((Handle)anImageDesc);
continue;
}
long rest;
movieRect->top = 0;
movieRect->left = 0;
movieRect->bottom = (*(ImageDescriptionHandle)anImageDesc)->height;
movieRect->right = (*(ImageDescriptionHandle)anImageDesc)->width;
DisposeHandle((Handle)anImageDesc);
}
}
return true;
}
-
Drawing in front of NSMovieView
2003-01-22 08:26:41 revuer [Reply | View]
I need to draw in front of a playing NSMovieView. I created a NSView subclass, and placed it over the NSMovieView. I "move[d] to back" the NSMovieView. It draws fine when I put an mp3 in the movie view, but when a .mov is playing, the image is superimposed over everything else. How do I draw in front of an NSMovieView? Not even a button, moved to the front, can be seen beneath it.
Do I need to do something regarding opacity? It shouldn't matter, as the custom view is in_front_of the movie.
-
How about a REAL QuickTime article?
2002-02-19 22:06:39 xylix [Reply | View]
I was quite disappointed in this article. I had high hopes when I read the first sentence:
"A number of readers have been asking for a column describing how to use Cocoa and QuickTime together"
but then he quickly goes on to say that he will show how to incorporate QuickTime media. I don't know about all of the other people who want to know "how to use Cocoa and QuickTime together" but this is NOT the point for me. In fact I would say this acticle has little to do with QuickTime if he is not using the API, it is simply a small app to play a .mov .mpg or .mp3 file. This needn't involve media created with QuickTime.
Please, please, please O'Reilly get someone to do the REAL article on how to use QuickTime in Cocoa -- ie some examples of using the QuickTime API. I just came across this site while trying to incorporate QuickTime into a Cocoa-Java app and the Apple documentation is not great - I can't even find the full API documentation for Java QuickTime.
Also, as a poster commented a month ago the link for the complete project doesn't work. Perhaps if either the author or O'Reilly people read this forum this can be corrected? -
How about a REAL QuickTime article?
2002-02-21 04:28:42 hellokopter [Reply | View]
I agree, this wasn't of much help at all. How about walking us through how to open up a port to a FireWire video device, capture a DV stream to disk, then, play it back out to another port? Or how to load a QuickTime movie and capture a single frame as an NSImage?
Does Apple have any plans to "Cocoa-ize" the older frameworks/Toolbox. I've looked at the QuickTime API and it's not very easy to figure it out. The language is all very foreign and complicated from a Cocoa/objective-c perspective. Apple has done a fabulous job with Cocoa, making many things accessible to new programmers, but there's still an almost insurmountable wall between the new stuff and the old (but still very important stuff like QuickTime).
-
Project Builder won't start
2002-02-11 07:01:46 wcostain [Reply | View]
I am having troubles getting project builder to start. When I try to open it I get a zoom rect and then nothing. Looking at the console tells me the following:
dyld: /Developer/Applications/Project Builder.app/Contents/MacOS/Project Builder can't open library: /System/Library/PrivateFrameworks/JavaKit.framework/Versions/A/JavaKit (No such file or directory, errno = 2)
I looked in the directory stated for the file JavaKit, and no it is not there. I have reinstalled the developer tools to no avail. Can you suggest anything?
Will -
Project Builder won't start
2003-08-26 17:10:35 anonymous2 [Reply | View]
I don't know about Project Builder but I had a similar problem with my TINI software. I Installed the latest JAVA and enabled JVM.
Java 2 SDK, Standard Edition
Version 1.4.2
Microsoft Windows
And tried all of the instructions in the TINI documentation. The comm.jar and win32com.dll have to be manually installed in the Java bin and lib directories. As well as resetting your path such as
SET PATH=C:\windows;C:\windows\command;C:\Progra~1\j2sdk_nb\j2sdk1~1.2\bin
I even tried setting a permanent classpath as some sites instructed to no avail.
This is my path to the new J2 SDK I also have a separate JAVA directory with a previous installation of Sun's JRE but I'm not going to worry about both right now.
After doing all of that the "getting started" instructions still failed to function with error messages about not being able to find the "main" .class I couldn't get the JavaKit to load much less worry about TINI programing.
To simplify matters I put the comm.jar file in the TINI directory. I finally found a website that gave step by step instructions for creating the command line to start the program. I then created a batch file with this command string. Yours will be different depending on your application and paths.
javaw -cp C:\TINI\bin\tini.jar;C:\TINI\comm.jar JavaKit
Bam, JavaKit came up with all of my ports listed Yea!
But no, there is no recognizable "JavaKit" file or application on my PC either, the closest is JavaKitSrc.jar and that is not directly useful.
That got the JavaKit GUI to materialize at least.
That's all I have to offer, I only achieved this small amount of success ten minutes ago after fighting with it all day. This is all new to me, but I hope you may find something useful in this post
-
Project Builder slightly out of tune?
2002-02-12 09:17:26 psheldon [Reply | View]
My working hypothesis I give you is this. "/System/Library/PrivateFrameworks...." is part of the os x system update and not the developer tools update. In os 9.x and earlier, the system file (and rom) manager routines were called by programs to make programming language higher than assembly level. Now, I suppose that we have a folder that holds these buidling tools, the folder above. I suspect that these "resources" are copied into program internals to give some sort of "continuity" to older os x programs. Even if the frameworks in the system folder change, many of the old programs continue to work, until you attempt to recompile the projects they come from. Then, you might have to do some "voodoo" with the includes and your intuition. I had to with a dumb speech program I made. Somehow, project builder itself is so fundamental that it can't "hold it's stuff", I bet.
When I get stuff on my developer cd's the dumb installs don't make me think about this distinction, if you get things from the free web site maybe it assumes you will have done the os x system update. I go to the apple store with my airport enhanced TiG4 and get the huge os x updates at high speed without sweating whether I need to.
I have a PB that works with the latest
1. os x 10.1.2
2. some sort of updater update
3. latest developer tools (how you identify such, I don't know)
Maybe if one of these dudes is out of synch PB won't work.
I suspect the new updater makes sure that the developer tools and os x system stuff are synchronized in some way.
That's the best guess I have to get you started.
-
Clean up
2002-01-31 19:37:56 michele [Reply | View]
I've added those methods to:
First: have the movie stop playing itself when closing occurs
- (void) windowWillClose: (NSNotification *)notif
{
[movieView stop: self];
}
Second: ensure that the view is not altered by some other views under it
- (BOOL) isOpaque
{
return YES;
}
Third: avoid potential memory leaks
- (void) dealloc
{
[movieView release];
[loopMenuItem release];
[super dealloc];
}
-
Resizing the window
2002-01-31 19:33:28 michele [Reply | View]
Here are two methods to resize the window and the movie at whatever magnification.
If someone could help me drawing it offscreen with Cocoa, it would be nicer to look at.
- (void) resizeMovieViewAndWindow: (float) magnification
{
NSSize movieViewFutureSize;
NSPoint topLeftPoint;
NSRect newFrame;
// Get the window and the frame view
NSWindow *movieWindow = [movieView window];
NSRect frameMovieView = [movieView frame];
// Get the movie size
NSSize movieViewNormalSize = [movieView sizeForMagnification: 1.0];
[movieView setNeedsDisplay: NO];
// Check if width is nil - for mp3s for example
// not sure for height if standard controller present: mini 16 pixels
// anyway does no harm to test it
if (movieViewNormalSize.width == 0.0 || movieViewNormalSize.height == 0.0)
{
// Set the width to length of controller, height to height of controller
movieViewFutureSize.width = frameMovieView.size.width;
movieViewFutureSize.height = 16;
}
// width is not nil
else
{
// Get the size of the view at magnification magnification
movieViewFutureSize = [movieView sizeForMagnification: magnification];
// Check if the size of the future view is less than the size of the min view as set in IB
if (movieViewFutureSize.width < [movieWindow minSize].width ||
movieViewFutureSize.height < [movieWindow minSize].height)
{
// Change the magnification to the max of magnification with minSize width
// and minSize height
magnification = fmax([movieWindow minSize].width / movieViewNormalSize.width,
[movieWindow minSize].height / movieViewNormalSize.height);
}
// Check if the size of the future view is more than the size of the max view as set in IB
if (movieViewFutureSize.width > [movieWindow maxSize].width ||
movieViewFutureSize.height > [movieWindow maxSize].height)
{
// Change the magnification to the min of magnification with maxSize width
// and maxSize height
magnification = fmin([movieWindow maxSize].width / movieViewNormalSize.width,
[movieWindow maxSize].height / movieViewNormalSize.height);
}
// Change the future size accordingly
movieViewFutureSize = [movieView sizeForMagnification: magnification];
// Resize the view's frame
[movieView resizeWithMagnification: magnification];
}
// Compute the window's frame according to movie view size
// and borders size
movieViewFutureSize.width += 2 * frameMovieView.origin.x;
movieViewFutureSize.height += 2 * frameMovieView.origin.y;
// Get the top left point of the window before resizing
// 22 is the height of the main menu bar
topLeftPoint = NSMakePoint([movieWindow frame].origin.x,
[movieWindow frame].origin.y -
movieViewFutureSize.height +
[movieWindow frame].size.height -
22);
newFrame = NSMakeRect(topLeftPoint.x, topLeftPoint.y, movieViewFutureSize.width, movieViewFutureSize.height);
// Set the window's content size to computed size
[movieWindow setContentSize: movieViewFutureSize];
//[movieWindow setFrame: newFrame display: NO];
// Set the top left point of the window after resizing
[movieWindow setFrameOrigin: topLeftPoint];
}
- (NSSize) windowWillResize: (NSWindow *) sender toSize: (NSSize) proposedFrameSize
{
// Initialize the magnification to 1.0
float newMagnification = 1.0;
// Retrieve the size of the view at magnification 1
NSSize normalFrameSize = [movieView sizeForMagnification: newMagnification];
// Check if the normal frame size width is not nil
if (!(normalFrameSize.width == 0.0 || normalFrameSize.height == 0.0))
{
// Computes the ratio between proposedFrameSize and movieViewNormalSize widths
// and heights. Take the minimum
newMagnification = fmin(proposedFrameSize.width / normalFrameSize.width,
proposedFrameSize.height / normalFrameSize.height);
}
// No resizing
else
{
NSBeep();
}
// Resizes the movie according to magnification
[self resizeMovieViewAndWindow: newMagnification];
return [sender frame].size;
}
-
Showing controller
2002-01-31 19:28:03 michele [Reply | View]
I've made some changes to the open method, so that one could open a wide variety of files known by QT, play them in background, always have a QT controller, display them at whatever magnification and not worry about closing them.
First : duplicated the name of types, as it appears that the types could be capitals or not.
Second: added some HFS file types, as some movies created on OS 9 and earlier do not have an extension of mov:
// Define the array of file types used for the movie in the open panel
NSArray *fileTypes = [NSArray arrayWithObjects :
@"mov", @"MOV", @"mpg", @"MPG", @"mp3", @"jpg", @"swf", @"avi", @"wav", @"aiff", @"midi",
@"mpeg", @"png", @"tiff", @"pict", @"gif", NSFileTypeForHFSTypeCode('Moov'), nil];
Third: autorelease the movie
NSMovie *myMovie = [[[NSMovie alloc] initWithURL: movieURL
byReference: NO] autorelease];
Fourth: add the movie's title
NSWindow *movieWindow = [movieView window];
[movieWindow setTitle: [[[myOpenPanel filenames] objectAtIndex: 0]
lastPathComponent]];
Fifth: display the controller taking in account the controller's size
[movieView showController: YES adjustingSize: YES];
Sixth: implemented a function to draw the movie at whatever magnification
[self resizeMovieViewAndWindow: 1.0];
Seventh: allowed play in background
[movieWindow makeKeyAndOrderFront: self];
Eighth: ensure that the controller redisplays after reopening an image file
[movieWindow display];
Michèle
-
How about JPGs and other Images?
2002-01-28 22:20:01 mhorn [Reply | View]
I do I go about using Quicktime and an NSImage together? Specifically, I would like to use the Quicktime scaling functions instead of the NSImage scaling functions since the Quicktime functions seem to provide much better results. -
How about JPGs and other Images?
2002-01-30 16:25:34 Michael Beam |
[Reply | View]
I've heard elsewhere that QuickTime does a better job at this kind of thing. NSMovie is a pretty lean class, and by the looks of it i think you would have to create an instance of NSImage using initWithContentsOfURL: in conjunction with NSMovie's -URL method.
So something like this:
NSImage *image = [[NSImage alloc] initWithURL:[movie URL]];
Does that help with your question?
Mike
-
Example not found
2002-01-27 13:22:04 michele [Reply | View]
Hello Mike,
The path given to download the project seems not to be valid.
Path: /a/mac/2002/01/25/mac/2002/01/25/examples/SimpleMoviePlayer.sit
Page not found
Michèle
-
How to put a NSMovieView into a NSCell?
2002-01-27 03:55:13 boz38 [Reply | View]
How can I wrap a movie into a NSCell?
-
FileTypes and resizing
2002-01-26 22:52:07 dimamarkman [Reply | View]
here is slightly modified version of openMovie,
that support HFS 'Moov" type and auto resizing
window
- (IBAction)openMovie:(id)sender
{
NSArray *fileTypes = [NSArray arrayWithObjects:@"mov", @"mpg", @"mp3",
@"jpg", @"swf",NSFileTypeForHFSTypeCode('MooV'),nil];
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
int result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes];
if (result == NSOKButton) {
NSWindow *window = [NSApp mainWindow];
NSRect frameView = [movieView frame];
NSSize viewSize;
NSArray *movieToOpen = [oPanel URLs];
NSURL *movieURL = [movieToOpen objectAtIndex:0];
NSMovie *movie = [[NSMovie alloc] initWithURL:movieURL byReference:NO];
[window setTitle:[[[oPanel filenames] objectAtIndex:0] lastPathComponent]];
[movieView setMovie:movie];
viewSize = [movieView sizeForMagnification:1.0];
[movieView resizeWithMagnification:1.0];
viewSize.width = 2*frameView.origin.x + viewSize.width;
viewSize.height = 2*frameView.origin.y + viewSize.height;
[window setContentSize:viewSize];
}
}
-
It doesn't play mp3's.
2002-01-26 18:09:16 psheldon [Reply | View]
At least for me.
;-) -
It doesn't play mp3's.
2002-01-31 19:52:14 michele [Reply | View]
It works perfectly for me using mp3s creating by iTunes2.
Maybe you have to change slightly the types defined in the array:
either by adding @"MP3"
or using the HFS file type (I don't know the exact file type, as I have no mp3 on OS9:
NSFileTypeForHFSTypeCode('filetypeformpg')
Another hint:
Try press the space bar, it could show the controller.
Or use what I did, show the controller at anytime:
// Display the controller taking in account the controller's size
[movieView showController: YES adjustingSize: YES];
Your code to resize the window at magnification 1.0
// Make the movie acccepts key and bring it to front
// to allow play in background
[movieWindow makeKeyAndOrderFront: self];
// Ensure that the controller redisplays after reopening a file
[movieWindow display];
-
Thanks, some observations
2002-02-01 09:58:56 psheldon [Reply | View]
I tried all your code and no controller appeared and then I decided to try the contextual menus. The one on the dock worked but not the one in the window.
I went back to the original project from the column without resizing and which I had set at a huge window in the IB. Both contextual menus worked and made the controller appear.
Now, I have your code to make isolations on.
I also did some fooling in IB with allowing a minimimum window size beyond default. That's my priority now. But, I seem to be getting lost so I may bounce between your code isolations too and this.
Definitely food for thought.
Thanks. -
some isolations
2002-02-01 11:16:34 psheldon [Reply | View]
I used the original nib file before I started messing with autoresizing.
I was able to comment out your file types and get some action.
Now, I've lost autoresizing code, for, when I try to use it, the movie window dissappears.
The best I can show you is the code with the resizing stuff commented out so the window doesn't dissappear. I don't know how to make a cleaner isolation or leaner question presentation than showing this.
- (IBAction)openMovie:(id)sender
{
NSArray *fileTypes = [NSArray arrayWithObjects:@"mov", @"mpg",
@"mp3",
//@"MP3",NSFileTypeForHFSTypeCode('MPG3'),//michele
@"jpg", nil];
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
int result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes];
if (result == NSOKButton)
{
//the following were added
NSWindow *window = [NSApp mainWindow];
NSRect frameView = [movieView frame];
NSSize viewSize;
NSArray *movieToOpen = [oPanel URLs];
NSURL *movieURL = [movieToOpen objectAtIndex:0];
NSMovie *movie = [[NSMovie alloc] initWithURL:movieURL byReference:NO];
[movieView showController:YES adjustingSize:YES];//michele
//the following were added (dimamarkman "FileTypes and Resizing" unless otherwise commented)
[window setTitle:[[[oPanel filenames] objectAtIndex:0] lastPathComponent]];
[movieView setMovie:movie];
//the following were added (dimamarkman "FileTypes and Resizing" unless otherwise commented)
//[movieView showController:YES adjustingSize:YES];//michele
//viewSize = [movieView sizeForMagnification:1.0];
//[movieView resizeWithMagnification:1.0];
[window makeKeyAndOrderFront: self];//michele
//viewSize.width = 2*frameView.origin.x + viewSize.width;
//viewSize.height = 2*frameView.origin.y + viewSize.height;
//[window setContentSize:viewSize];
[window display];//michele
}
}
-
some isolations
2002-02-01 13:11:27 michele [Reply | View]
Post a Reply
Article:
Movies and Menus
Subject: some isolations
Date: 2002-02-01 11:16:34
From: psheldon
Response to: Thanks, some observations
------------------------------------------------------------------------
I used the original nib file before I started messing with autoresizing.
I was able to comment out your file types and get some action.
Now, I've lost autoresizing code, for, when I try to use it, the movie window dissappears.
The best I can show you is the code with the resizing stuff commented out so the window doesn't dissappear. I don't know how to make a cleaner isolation or leaner question presentation than showing this.
- (IBAction)openMovie:(id)sender
{
NSArray *fileTypes = [NSArray arrayWithObjects:@"mov", @"mpg",
@"mp3", @"jpg", nil];
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
int result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes];
if (result == NSOKButton)
{
NSRect frameView = [movieView frame];
NSSize viewSize;
NSArray *movieToOpen = [oPanel URLs];
NSURL *movieURL = [movieToOpen objectAtIndex:0];
NSMovie *movie = [[NSMovie alloc] initWithURL:movieURL byReference:NO];
if you don't autorelease here, you'll have to do it later.
This line:
NSWindow *window = [NSApp mainWindow];
is strictly equivalent to this one:
NSWindow *movieWindow = [movieView window];
because there is only one window at a time, this is the main window and
there is an outlet defined in Controller.h: IBOutlet NSMovieView *movieView;
This outlet is connected from Controller to NSMovieView view.
[window setTitle:[[[oPanel filenames] objectAtIndex:0] lastPathComponent]];
You'll have to set the movie, before showing the controller, resizing the view, make it key and displaying it, otherwise, the controller could not show and the size could not be adjusted to your movie.
[movieView setMovie:movie];
[movieView showController:YES adjustingSize:YES];//michele
Here comes the code for resizing window
In the nib file, do not set any springs to the custom view, because it would be applied when you resize together with the code for resizing. Then it'll be bloody.
For example: I've made the view in nib file: 20, 20 for margins 292, 203 for width and height
the window: 21, 53 for the margins 339, 243 for width and height
minimum size: 221, 153 maximum size: 800, 600
// Draw the movie at magnification 1
viewSize = [movieView sizeForMagnification:1.0];
[movieView resizeWithMagnification:1.0];
viewSize.width = 2*frameView.origin.x + viewSize.width;
viewSize.height = 2*frameView.origin.y + viewSize.height;
[window setContentSize:viewSize];
[window makeKeyAndOrderFront: self];//michele
[window display];//michele
}
}
Hope this helps you
Michèle
-
tried your ordering and no springs
2002-02-02 10:27:24 psheldon [Reply | View]
Note I have done mnc, minimum necessary change (actually alleged necessary change). My point is to not merely get something that works, but to learn how to isolate why something doesn't work, a much harder task but hope doable and rewarding. I don't have confidence in isolating my own mistakes in cocoa and "fear the old days" of spending huge amounts of time in debugging and being beat up by old men who had "gone to the dark side of the force" to judge others who couldn't get "death stars" operational in time.
Coding should be better than that. When I saw Inside Mac with its "managers" I thought to obsoletize these bogeys.
So, here goes mnc (from Sci Fi, "The End of Eternity", where misguided folks debug history and Noise Lambent teaches them another way):
- (IBAction)openMovie:(id)sender
{
NSArray *fileTypes = [NSArray arrayWithObjects:@"mov", @"mpg",
@"mp3",
@"gif",//my addition (works)
//@"MP3",NSFileTypeForHFSTypeCode('MPG3'),//michele
@"jpg", nil];
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
int result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes];
if (result == NSOKButton)
{
//the following were added
//NSWindow *window = [NSApp mainWindow];//(dimamarkman)
NSWindow *window = [movieView window];//michele
NSRect frameView = [movieView frame];
NSSize viewSize;
NSArray *movieToOpen = [oPanel URLs];
NSURL *movieURL = [movieToOpen objectAtIndex:0];
NSMovie *movie = [[[NSMovie alloc] initWithURL:movieURL byReference:NO] autorelease];
//must come first --- michele
[movieView setMovie:movie];
//no springs in nib file --- michele (I cleaned target just to be safe)
//the following were added (dimamarkman unless otherwise commented)
[movieView showController:YES adjustingSize:YES];//michele
[window setTitle:[[[oPanel filenames] objectAtIndex:0] lastPathComponent]];
//the following were added (dimamarkman unless otherwise commented)
viewSize = [movieView sizeForMagnification:1.0];
[movieView resizeWithMagnification:1.0];
viewSize.width = 2*frameView.origin.x + viewSize.width;
viewSize.height = 2*frameView.origin.y + viewSize.height;
[window setContentSize:viewSize];
[window makeKeyAndOrderFront: self];//michele
[window display];//michele
}
}
- (IBAction)playMovie:(id)sender
{
[movieView start:self];
}
- (IBAction)pauseMovie:(id)sender
{
[movieView stop:self];
}
- (IBAction)toggleLoopMode:(id)sender
{
if ( [ContextualMenuToggleLoopItem state] == NSOnState ) {
[ContextualMenuToggleLoopItem setState:NSOffState];
[movieView setLoopMode:NSQTMovieNormalPlayback];
} else {
[ContextualMenuToggleLoopItem setState:NSOnState];
[movieView setLoopMode:NSQTMovieLoopingPlayback];
}
}
-
forgot to tell fact
2002-02-02 10:32:53 psheldon [Reply | View]
Window only disappears when I try to play an mp3! Sorry. Caught my omission immediately!
-
thanks michele
2002-02-03 21:56:46 psheldon [Reply | View]
Had to get a clear idea of what was going on to eliminate to the dumb fix. If folks had just left my question out there, I might have not gotten up enough pizzaz to go look for the obvious.
Gotta remember to thank and not merely congratulate myself when I get the fix, so that other folks keep their pizzaz. -
added if before size adjustment to avoid mp3's
2002-02-02 18:50:56 psheldon [Reply | View]
if (viewSize.width != 0 && viewSize.height != 0)
{
[movieView showcontroller:YES adjustingSize:YES];
...
}
else
[movieView showcontroller:YES adjustingSize:NO];
and it worked. So, my last second inclusion in above note on leaving the problem awhile proved the answer! I debugged myself in cocoa.
-
disabled files in oPanel
2002-01-26 18:07:49 psheldon [Reply | View]
Should have, at one time, mov as suffix and then can remove it to have it active in oPanel display.
I suppose something changed about file type and creator in os x. But then, you need to have the suffix all the time. I think the finder is doing something mysterious, but how do we brief it into a generality. -
disabled files in oPanel
2002-01-31 19:56:10 michele [Reply | View]
In OSX, there is always a suffix, event if it is hidden. So for OSX files, use the @"mov" and @"MOV" strings in array.
For OS9 files, the suffix are not always here so use the type:
NSFileTypeForHFSTypeCode('Moov')
in array
Hope this helps
Michèle
-
What is convenience constructor?
2002-01-26 18:02:52 psheldon [Reply | View]
You covered it in memory management, but restatement might clarify.
These instances are used to make objects such as dialog boxes or quicktime windows on the screen, say attached to instantiations of IB, but when no longer needed to build into stuff in the nib file can go away but the nib associations hang around until the program quits.
I don't like the way I worded the above and think that maybe someone could make a better brief.
-
Resizing movie views
2002-01-26 00:01:14 pdwilson12 [Reply | View]
You can obtain the true size of a movie after it is placed in a movie view by using NSMovieView's sizeForMagnification: method with a magnification of 1.0. Note that the returned size assumes you are displaying the 16-pixel high movie controller in the view as well. You can also resize the view directly by using the resizeForMagnification: method.
-
Resizing movie views
2002-01-31 20:03:04 michele [Reply | View]
"Note that the returned size assumes you are displaying the 16-pixel high movie controller in the view as well."
Not exactly, by default, we have:
[movieView showController: YES adjustingSize: NO];
so it does not adjust the size taking into account the controller's size, it resizes the view so that the controller appears in the window.
If you use
[movieView showController: YES adjustingSize: YES];
the height of the controller is added to the height of the movie to resize the view.
Michèle
-
Resizing movie views
2002-01-26 20:36:03 ryan_dingman [Reply | View]
It is also worth noting that you can obtain the size of a movie without needing an NSMovieView. You can ask NSMovie for its QuickTime movie with -[NSMovie QTMovie] and then use GetMovieNaturalBoundsRect() to get its size. The following category on NSMovie is generally useful.
@implementation NSMovie (NSMovieExtensions)
- (NSSize)size;
{
Movie movie;
Rect movieRect;
movie = [self QTMovie];
GetMovieNaturalBoundsRect(movie, &movieRect);
return NSMakeSize(movieRect.right - movieRect.left, movieRect.bottom - movieRect.top);
}
@end
Hope this helps.
ryan
--
Ryan Dingman
FrontBase, Inc.
ryan@frontbase.com
-
Resizing movie views
2002-02-01 13:15:36 michele [Reply | View]
Hi Ryan,
This code does not work for me.
I've got an error on the line:
movie=[self QTMovie];
I'll guess I have to add the QT framework for it to work.
Anyway, it does not resolve the resizing at whatever magnification, or am I missing something?
Michèle
-
Add Loop Menu Outlet
2002-01-25 22:04:28 johnts [Reply | View]
Ok, since I couldn't download the sample code, I went and tried my hand at adding the outlet for the Loop menu to get rid of the runtime errors. And it seems I did it (mostly) right. It don't get the error anymore, but when i select the Loop menu it doesn't set the check mark on the dock menu. It will show a checkmark in the popup menu though. Thoughts?? Thanks!






I have posted this in various sites and could not get proper solution. Kindly ignore it, if this is not the right place to discuss this.
I have been working on a client-server based application which got a feature similar to iTunes sharing. That is I want to share movie files between machines over the LAN.Currently on server side, I have created a socket , write the movie data to that socket. On client side I am saving the remote movie data to the a temporary file and giving this local file as input to QuickTime. But it got an issue with QuickTIme updating the movie play if all of the data is in place. i.e QuickTime not plalying with complete data.
Could anybody please help me out by giving a work around for this. Is there any way that I can do stream movie data into a QTMovie/QuickTime. As I explained above the scenario is that I have movie data streaming in over a socket and I'd like to feed that data into a QTMovie/QuickTime and start playing the movie before all of the data is in place. i.e I need a way to tell Quicklime/QTMove to look input as remote socket.
As I am totally new to QuickTime/QTmovie programing , kind ly correct me if I am doing something wrong.
Any help in this regard is greatly appreciated.
Thanks,
Abdul Majeed K