Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Quicktime is not reloading audio files.



Hello All,

I put in a request for assistance on this issue a couple of weeks back. I have finally had time to get some simple example code working. What is happening is that I am recording an audio file using Java sound, but playing it back with Quicktime. When I go to play the audio with Quicktime the first time, it is perfect. Then I replace the audio and try to play the new audio file with the same name. What happens is that the first audio file is played. Quicktime appears to be caching the audio file. In the example code I have here, it will take the name of two audio files as input. It creates a copy of the first audio and plays it. Then it replaces that audio with the second audio and tries to play it. However, the first audio is played instead. I appreciate any assistance.

thanks,

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import quicktime.QTException;
import quicktime.QTSession;
import quicktime.app.time.TaskAllMovies;
import quicktime.io.OpenMovieFile;
import quicktime.io.QTFile;
import quicktime.std.movies.Movie;

/**
 *
 */

/**
 * @author user
 *
 */
public class QuicktimeTest {

 /**
  * @param args
  */
 public static void main(String[] args) {

  try {
   QTSession.open();

File firstOriginalFile = new File(args[0]);
File tempPlayFile = new File(firstOriginalFile.getParentFile(), "tempAudio.m4a");
copyFile(firstOriginalFile, tempPlayFile);
Movie movie = playMovie(tempPlayFile);


   while(!movie.isDone()){
    try {
     Thread.sleep(100);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }

   tempPlayFile.delete();
   File secondOriginalFile = new File(args[1]);
   copyFile(secondOriginalFile, tempPlayFile);
   movie = playMovie(tempPlayFile);

   while(!movie.isDone()){
    try {
     Thread.sleep(100);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }

   tempPlayFile.delete();
   QTSession.close();

  } catch (QTException e) {

   e.printStackTrace();
  } catch (IOException e) {

   e.printStackTrace();
  }


}

 public static Movie playMovie(File file) throws QTException{
  QTFile f = new QTFile(file);
  OpenMovieFile omf = OpenMovieFile.asRead(f);
  Movie movie = Movie.fromFile(omf);
  TaskAllMovies.addMovieAndStart();
  movie.start();
  return movie;
 }

/**
* Copies the target file or folder into the destination folder.
*
* @param target
* A file or folder to be copied.
* @param destination
* A folder where the target is to be copied into.
* @throws BackupReplicationException
*/
private static void copyFile(File target, File destination) throws IOException {


  // If the target file does not exist, return
  if (target == null || !target.exists()) {

   throw new IOException(target.getPath() + " does not exist.");
  }

  if (target.isFile()) {

   // Create the subdirectories where the file will go into.
   destination.getParentFile().mkdirs();

   // Create the file where the data will be copied into.
   if (!destination.exists()) {

    destination.createNewFile();
   }

   InputStream inputStream = new BufferedInputStream(
     new FileInputStream(target));
   OutputStream outputStream = new BufferedOutputStream(
     new FileOutputStream(destination));
   byte[] copyData = new byte[256];
   int length;
   while ((length = inputStream.read(copyData)) != -1) {

    outputStream.write(copyData, 0, length);
    outputStream.flush();
   }

   inputStream.close();
   outputStream.close();
  }
 }
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-java mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-java/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.