FileDocCategorySizeDatePackage
AudioPlaybackHandler.javaAPI DocAndroid 5.1 API4162Thu Mar 12 22:22:10 GMT 2015android.speech.tts

AudioPlaybackHandler

public class AudioPlaybackHandler extends Object

Fields Summary
private static final String
TAG
private static final boolean
DBG
private final LinkedBlockingQueue
mQueue
private final Thread
mHandlerThread
private volatile PlaybackQueueItem
mCurrentWorkItem
Constructors Summary
AudioPlaybackHandler()


     
        mHandlerThread = new Thread(new MessageLoop(), "TTS.AudioPlaybackThread");
    
Methods Summary
public voidenqueue(PlaybackQueueItem item)

        try {
            mQueue.put(item);
        } catch (InterruptedException ie) {
            // This exception will never be thrown, since we allow our queue
            // to be have an unbounded size. put() will therefore never block.
        }
    
public booleanisSpeaking()

return
false iff the queue is empty and no queue item is currently being handled, true otherwise.

        return (mQueue.peek() != null) || (mCurrentWorkItem != null);
    
public voidquit()
Shut down the audio playback thread.

        removeAllMessages();
        stop(mCurrentWorkItem);
        mHandlerThread.interrupt();
    
private voidremoveAllMessages()

        mQueue.clear();
    
private voidremoveWorkItemsFor(java.lang.Object callerIdentity)

        Iterator<PlaybackQueueItem> it = mQueue.iterator();

        while (it.hasNext()) {
            final PlaybackQueueItem item = it.next();
            if (item.getCallerIdentity() == callerIdentity) {
                it.remove();
            }
        }
    
public voidstart()

        mHandlerThread.start();
    
private voidstop(PlaybackQueueItem item)

        if (item == null) {
            return;
        }

        item.stop(TextToSpeech.STOPPED);
    
public voidstop()

        if (DBG) Log.d(TAG, "Stopping all items");
        removeAllMessages();

        stop(mCurrentWorkItem);
    
public voidstopForApp(java.lang.Object callerIdentity)

        if (DBG) Log.d(TAG, "Removing all callback items for : " + callerIdentity);
        removeWorkItemsFor(callerIdentity);

        final PlaybackQueueItem current = mCurrentWorkItem;
        if (current != null && (current.getCallerIdentity() == callerIdentity)) {
            stop(current);
        }