FileDocCategorySizeDatePackage
AwaitableErrorListener.javaAPI DocAndroid 5.1 API2349Thu Mar 12 22:22:48 GMT 2015com.android.ex.variablespeed

AwaitableErrorListener

public class AwaitableErrorListener extends Object implements MediaPlayer.OnErrorListener
Implementation of {@link MediaPlayer.OnCompletionListener} that we can wait for in tests.

Fields Summary
private final BlockingQueue
mQueue
private volatile boolean
mOnErrorReturnValue
Constructors Summary
Methods Summary
private voidaddAnObjectToTheQueue()

        try {
            mQueue.put(new Object());
        } catch (InterruptedException e) {
            // This should not happen in practice, the queue is unbounded so this method will not
            // block.
            // If this thread is using interrupt to shut down, preserve interrupt status and return.
            Thread.currentThread().interrupt();
        }
    
public voidassertNoMoreCallbacks()

        if (mQueue.peek() != null) {
            throw new IllegalStateException("there was an unexpected callback on the queue");
        }
    
public voidawaitOneCallback(long timeout, java.util.concurrent.TimeUnit unit)

        if (mQueue.poll(timeout, unit) == null) {
            throw new TimeoutException();
        }
    
public booleanonError(android.media.MediaPlayer mp, int what, int extra)


    
            
        addAnObjectToTheQueue();
        return mOnErrorReturnValue;
    
public voidsetOnErrorReturnValue(boolean value)

        mOnErrorReturnValue = value;