/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityThread; import android.content.ContentResolver; import android.content.Context; import android.content.res.AssetFileDescriptor; import android.net.Uri; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.Parcel; import android.os.Parcelable; import android.os.Process; import android.os.PowerManager; import android.os.SystemProperties; import android.provider.Settings; import android.system.ErrnoException; import android.system.OsConstants; import android.util.Log; import android.util.Pair; import android.view.Surface; import android.view.SurfaceHolder; import android.widget.VideoView; import android.graphics.SurfaceTexture; import android.media.AudioManager; import android.media.MediaFormat; import android.media.MediaTimeProvider; import android.media.PlaybackParams; import android.media.SubtitleController; import android.media.SubtitleController.Anchor; import android.media.SubtitleData; import android.media.SubtitleTrack.RenderingWidget; import android.media.SyncParams; import com.android.internal.util.Preconditions; import libcore.io.IoBridge; import libcore.io.Libcore; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.Runnable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.net.InetSocketAddress; import java.util.BitSet; import java.util.Map; import java.util.Scanner; import java.util.Set; import java.util.Vector; import java.lang.ref.WeakReference; /** * MediaPlayer class can be used to control playback * of audio/video files and streams. An example on how to use the methods in * this class can be found in {@link android.widget.VideoView}. * *

Topics covered here are: *

    *
  1. State Diagram *
  2. Valid and Invalid States *
  3. Permissions *
  4. Register informational and error callbacks *
* *
*

Developer Guides

*

For more information about how to use MediaPlayer, read the * Media Playback developer guide.

*
* * *

State Diagram

* *

Playback control of audio/video files and streams is managed as a state * machine. The following diagram shows the life cycle and the states of a * MediaPlayer object driven by the supported playback control operations. * The ovals represent the states a MediaPlayer object may reside * in. The arcs represent the playback control operations that drive the object * state transition. There are two types of arcs. The arcs with a single arrow * head represent synchronous method calls, while those with * a double arrow head represent asynchronous method calls.

* *

MediaPlayer State diagram

* *

From this state diagram, one can see that a MediaPlayer object has the * following states:

*