QuickTimeMovieComponent and Movie URL

Hi all,
QuickTime Player plays movie which are available online, if the URL are provided. Is it possible to do the same with QuickTimeMovieComponent of juce.

In this regard, I can see this method.

If I create a InputStream out of the url and feed it to this method will it download and preview the video or buffer the contents of the file and start playing? Any help on this would be appreciated.

I think it might download the whole thing first, though could probably be made a bit smarter to cope with that…

Hi Jules,
I tried playing a movie from a URL. But the quicktime component didn’t play it. This is my code.

void MoviePlayer::buttonClicked (juce::Button *button)
{
	juce::URL url(urlString);
	juce::InputStream * stream = url.createInputStream (true);
	
	if (stream != 0L && _pQTComponent != 0L)
	{
		bool status = _pQTComponent->loadMovie (stream,true);
       // status is false
      if (status)
	       _pQTComponent->play ();
      else
           juce::Logger::outputDebugString(T("failed to load the movie"));
	}	
}

The Component is visible. It displays a blank screen.

I debugged into juce_mac_QuickTimeMovieComponent.mm.

static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
{
    // unfortunately, QTMovie objects can only be created on the main thread..
    jassert (MessageManager::getInstance()->isThisTheMessageThread());

    QTMovie* movie = 0;

    FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);

    if (fin != 0)
    {
        movieFile = fin->getFile();
        movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
                                 error: nil];
    }
    else
    {
        MemoryBlock temp;
        movieStream->readIntoMemoryBlock (temp);

        const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };

        for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
        {
            movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
                                                                                                                       length: temp.getSize()]
                                                                                                  name: [NSString stringWithCString: suffixesToTry[i]]
                                                                                              MIMEType: @""]
                                              error: nil];
           // movie is null, so it doesn't play the video
            if (movie != 0)
                break;
        }
    }

    return movie;
}

I am trying to play a mov file. I haven’t tested this on Windows, this is the result in SL.

Hi Jules,
I have added a couple of methods to play from web on mac.

bool QuickTimeMovieComponent::loadMovie (const URL& fileUrl, const bool isControllerVisible)
{
	closeMovie();
	
    if (getPeer() == 0)
    {
			// To open a movie, this component must be visible inside a functioning window, so that
			// the QT control can be assigned to the window.
        jassertfalse
        return false;
    }
	
    movie = openMovieFromURL (fileUrl);
	
    [theMovie retain];
    QTMovieView* view = (QTMovieView*) getView();
    [view setMovie: theMovie];
    [view setControllerVisible: controllerVisible];
    setLooping (looping);
	
    return movie != nil;
}

static QTMovie* openMovieFromURL (const URL& fileUrl)
{
	// unfortunately, QTMovie objects can only be created on the main thread..
    jassert (MessageManager::getInstance()->isThisTheMessageThread());
	
	QTMovie* movie = 0;
	
	if (fileUrl.isWellFormed ())
	{
		juce::String urlString = fileUrl.toString (true);
		NSURL *url = [NSURL URLWithString :juceStringToNS(fileUrl.toString (true))];
		NSError *error;
		if ([ QTMovie canInitWithURL:url ])
			movie = [QTMovie movieWithURL:url error:&error];
		
	}
	return movie;
}

Ah, many thanks - I’d been meaning to add that method!

It’s always a pleasure Jules :smiley: . I have a question though. Can I use QTMovie to download a movie using Quicktime framework. I know it’s not the right place to ask this question but does anybody know :?: .

Not sure exactly what you’re asking? You mean download and save it locally?

Yes, I want to preview and optionally download the file to local drive.I went through the Quicktime Documentation couldn’t find any method for doing it using Quictime.

Ended up using NSURLDownload to download the file.

My requirement is a little weird, I have to preview the video (from internet) if it’s not available locally on the user machine. If user has set the option “preview and download”, my application should download and also preview the movie simultaneously.

Why did you go for a native download call rather than just using opening a stream with the URL class and shoving it into a file?

You are right, looks like I got a little carried away with cocoa.

Hi Jules,
Any ideas on how I can get quicktimecomponent to preview movies from web on windows ?

Can’t really remember offhand. It must have some kind of function to let it open a URL though?

The documentation looked straight forward for Macintosh. Not able to find documentation for windows. It would be helpful if I could get the documentation.

Anyway I will give it a try tomorrow and get back to you.

Hi,

Im facing a similar problem on Windows…I would like to stream a movie from the web using juce::QuickTimeMovieComponent(juce1_50)…Is there any way I could do that…

Thanks,
Pravi