• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Play a song with QTMovie
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Play a song with QTMovie


  • Subject: Re: Play a song with QTMovie
  • From: Dani <email@hidden>
  • Date: Tue, 26 Jun 2007 14:46:33 +0200

I've tried making a new Cocoa Application project with Xcode, and now it seems to work well, but now I don't know how to check if a song is currently playing or not.
I've make an interface with 2 buttons, one for start playing a song and another to stop current song, so I've got something like this in the @implementation file :


- (IBAction)play:(id)sender
{

	src = @"/Users/bittercold/Desktop/deadbolt.aif";
	snd = [[QTMovie alloc] initWithFile:src error: NULL];
	[snd play];
}

- (IBAction)stop:(id)sender
{
	[snd stop];
}

and this in the @interface file:

@interface PlaySong : NSObject
{
	NSString *src;
	QTMovie *snd;
}
- (IBAction)play:(id)sender;
- (IBAction)stop:(id)sender;
@end

It's obvious that when I click the Play button for the first time it'll work, but if I press a second time, it'll create a new instance of QTMovie. Am I wrong? So, how can I check if there's another song currently playing to prevent creating a new one? Thanks

El 26/06/2007, a las 12:02, Stephane Sudre escribió:

No, I was referring to a NSRunLoop.



On 26 juin 07, at 11:56, Dani wrote:

Thanks. I'll try that.

When you says "have a run loop" are you talking about something like:

while([song rate]<100.0)
{}


El 26/06/2007, a las 11:44, Stephane Sudre escribió:


On 26 juin 07, at 10:59, Dani . wrote:

Hi! I've been reading every message about how to play a song with
cocoa, and finally I can't find anything that works. I've made a
simple code, and I want to know what I am doing wrong. Thanks

#import <Foundation/Foundation.h>
#import <QTKit/QTMovie.h>

int main (int argc, const char * argv[]) {

	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];


	NSString *src = @"/Users/bittercold/Desktop/deadbolt.aiff";
	QTMovie *song = [[QTMovie alloc] initWithFile:src error: NULL];
	[song play];

	[pool release];
	return 0;
}

I think the key is in the difference between asynchronous and synchronous.


When you call play, it continues immediately and does not wait for the song to be played.

What you may want to do is to:

- have a run loop

- install a notification observer for the end of the playback and stop the application a this point.

As I usually do this through a QTMovieView, I can't confirm just using [QTMovie play] can work for a song.




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Play a song with QTMovie
      • From: "R. Matthew Emerson" <email@hidden>
    • Re: Play a song with QTMovie
      • From: Stephane <email@hidden>
References: 
 >Play a song with QTMovie (From: "Dani ." <email@hidden>)
 >Re: Play a song with QTMovie (From: Stephane Sudre <email@hidden>)
 >Re: Play a song with QTMovie (From: Stephane Sudre <email@hidden>)

  • Prev by Date: Re: Shared code in multiple plug-ins.
  • Next by Date: Drawing from upper left
  • Previous by thread: Re: Play a song with QTMovie
  • Next by thread: Re: Play a song with QTMovie
  • Index(es):
    • Date
    • Thread