Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Movies and Menus
Subject:   It doesn't play mp3's.
Date:   2002-01-26 18:09:16
From:   psheldon
At least for me.
;-)
Full Threads Oldest First

Showing messages 1 through 8 of 8.

  • It doesn't play mp3's.
    2002-01-31 19:52:14  michele [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 [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 [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 [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 [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 [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 [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 [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.