Re: beginner's question (Cocoa + QT)
Re: beginner's question (Cocoa + QT)
- Subject: Re: beginner's question (Cocoa + QT)
- From: Steve Poole <email@hidden>
- Date: Thu, 24 May 2001 09:12:41 -0700
Thanks very much for your help, aNt. I have it playing exactly the way I
want in a simple Java application now. Thanks also to Dean Perry for
pointing out the importance of our friend the MovieController.
Now I'm back to where I started...it doesn't work properly in a Cocoa
application. I'm crossposting to the Cocoa dev list. Here's the deal:
I want to play a QuickTime audio stream from a Cocoa app written in
Java. I'm using QuickTime for Java. The code runs just fine in a
non-Cocoa Java app, but in a butt-simple Cocoa app it begins playing but
then fails. Here's my test case.
1) Make a Cocoa Java app in ProjectBuilder. Add QTJava.zip from the Java
1.3 framework.
2) Open the nib in InterfaceBuilder. Add a button to the existing window.
3) In IB add class CocoaPlayerTest extending java.lang.Object. Add a
startPlayer() action.
4) Connect the button's target to the startPlayer action().
5) Instantiate the CocoaPlayerTest class and generate code.
6) Add the CocoaPlayerTest.java class to the project in PB.
7) Modify the CocoaPlayerTest.java class:
import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
import quicktime.*;
import quicktime.io.QTFile;
import quicktime.app.QTFactory;
import quicktime.app.display.*;
import quicktime.app.players.*;
import quicktime.app.image.ImageDrawer;
import quicktime.std.*;
import quicktime.std.movies.*;
import quicktime.std.movies.media.*;
public class CocoaPlayerTest
{
private QTPlayer mPlayer;
private QTCanvas mQTCanvas;
private Movie mMovie;
private MovieController mController;
public void
startPlayer(
NSButton sender )
{
try
{
QTSession.open();
String URL = "
http://www.shoutcast.com/sbin/shoutcast-
playlist.pls?addr=205.188.245.132:8002&file=filename.pls";
mPlayer = (QTPlayer)QTFactory.makeDrawable( URL );
mController = mPlayer.getMovieController();
mController.setVisible( false );
Movie movie = mController.getMovie();
mPlayer.startTasking();
mPlayer.setRate( 1.0f );
}
catch( Exception e )
{
e.printStackTrace();
QTSession.close();
}
}
}
8) Build and run. Click the button and the stream will begin playing.
9) Now drag the window, click something in the dock, or generally
disturb the peace. One of two things happens: The stream stops playing,
or the stream continues playing but the application's UI becomes
basically inert. The button no longer tracks, menus may or may not work,
etc. Using top I see that CPU usage for the app has dropped from where
it is when the stream is playing, but is still greater than what it is
before the stream has started.
Any thoughts? Help is much appreciated. I'd hate to have to write my app
in C++ and Carbon!
Steve