FileDocCategorySizeDatePackage
MediaPlayerStressTest.javaAPI DocAndroid 5.1 API6257Thu Mar 12 22:22:30 GMT 2015com.android.mediaframeworktest.stress

MediaPlayerStressTest

public class MediaPlayerStressTest extends android.test.ActivityInstrumentationTestCase2
Junit / Instrumentation test case for the media player

Fields Summary
private String
TAG
private String
mMediaSrc
private int
mTotalPlaybackError
private int
mTotalComplete
private int
mTotalInfoUnknown
private int
mTotalVideoTrackLagging
private int
mTotalBadInterleaving
private int
mTotalNotSeekable
private int
mTotalMetaDataUpdate
private static final String
PLAYBACK_RESULT
Constructors Summary
public MediaPlayerStressTest()


      
        super("com.android.mediaframeworktest", MediaFrameworkTest.class);
    
Methods Summary
protected voidsetUp()

        //Insert a 2 second before launching the test activity. This is
        //the workaround for the race condition of requesting the updated surface.
        Thread.sleep(2000);
        getActivity();
        MediaPlayerStressTestRunner mRunner = (MediaPlayerStressTestRunner)getInstrumentation();
        Bundle arguments = mRunner.getArguments();
        mMediaSrc = arguments.getString("media-source");
        if (mMediaSrc == null) {
            mMediaSrc = MediaNames.MEDIA_SAMPLE_POOL;
        }
        super.setUp();
    
public voidtestVideoPlayback()

        String fileWithError = "Filename:\n";
        File playbackOutput = new File(Environment.getExternalStorageDirectory(), PLAYBACK_RESULT);
        Writer output = new BufferedWriter(new FileWriter(playbackOutput, true));

        boolean testResult = true;
        // load directory files
        boolean onCompleteSuccess = false;
        String[] children = MediaNames.NETWORK_VIDEO_FILES;
        if (MediaNames.MEDIA_SAMPLE_POOL.equals(mMediaSrc)) {
            File dir = new File(mMediaSrc);
            children = dir.list();
        }
        if (children == null) {
            Log.v("MediaPlayerApiTest:testMediaSamples", "dir is empty");
            return;
        } else {
            for (int i = 0; i < children.length; i++) {
                //Get filename
                String filename = children[i];
                onCompleteSuccess =
                    CodecTest.playMediaSamples(mMediaSrc + filename);
                if (!onCompleteSuccess){
                    //Don't fail the test right away, print out the failure file.
                    fileWithError += filename + '\n";
                    Log.v(TAG, "Failure File : " + fileWithError);
                    testResult = false;
                }
                Thread.sleep(3000);
                //Write test result to an output file
                writeTestOutput(filename,output);
                //Get the summary
                updateTestResult();
            }
            writeTestSummary(output);
            output.close();
            assertTrue("testMediaSamples", testResult);
       }
    
private voidupdateTestResult()

        if (CodecTest.onCompleteSuccess){
            mTotalComplete++;
        }
        else if (CodecTest.mPlaybackError){
            mTotalPlaybackError++;
        }
        mTotalInfoUnknown += CodecTest.mMediaInfoUnknownCount;
        mTotalVideoTrackLagging += CodecTest.mMediaInfoVideoTrackLaggingCount;
        mTotalBadInterleaving += CodecTest.mMediaInfoBadInterleavingCount;
        mTotalNotSeekable += CodecTest.mMediaInfoNotSeekableCount;
        mTotalMetaDataUpdate += CodecTest.mMediaInfoMetdataUpdateCount;
    
private voidwriteTestOutput(java.lang.String filename, java.io.Writer output)


           
        output.write("File Name: " + filename);
        output.write(" Complete: " + CodecTest.onCompleteSuccess);
        output.write(" Error: " + CodecTest.mPlaybackError);
        output.write(" Unknown Info: " + CodecTest.mMediaInfoUnknownCount);
        output.write(" Track Lagging: " +  CodecTest.mMediaInfoVideoTrackLaggingCount);
        output.write(" Bad Interleaving: " + CodecTest.mMediaInfoBadInterleavingCount);
        output.write(" Not Seekable: " + CodecTest.mMediaInfoNotSeekableCount);
        output.write(" Info Meta data update: " + CodecTest.mMediaInfoMetdataUpdateCount);
        output.write("\n");
    
private voidwriteTestSummary(java.io.Writer output)

        output.write("Total Result:\n");
        output.write("Total Complete: " + mTotalComplete + "\n");
        output.write("Total Error: " + mTotalPlaybackError + "\n");
        output.write("Total Unknown Info: " + mTotalInfoUnknown + "\n");
        output.write("Total Track Lagging: " + mTotalVideoTrackLagging + "\n" );
        output.write("Total Bad Interleaving: " + mTotalBadInterleaving + "\n");
        output.write("Total Not Seekable: " + mTotalNotSeekable + "\n");
        output.write("Total Info Meta data update: " + mTotalMetaDataUpdate + "\n");
        output.write("\n");