为什么vlc media playerplayerif

1059人阅读
Android(3)
通过参照网上其他人的MP3播放器,自己也在这些基础上小试牛刀,制作的了一个MP3的播放器,先上个界面先:
接下来就上代码:
首先是.mp3格式的音乐文件的过滤类单独在一个java文件中:
package com.example.
import java.io.F
import java.io.FilenameF
public class MusicFilter implements FilenameFilter{
public boolean accept(File dir, String filename) {
// TODO Auto-generated method stub
return (filename.endsWith(&.mp3&));
下面是MainActivity.java中的代码(其中音量和播放进度的方法是参照网上别人的):
package com.example.
import java.io.F
import java.util.ArrayL
import java.util.HashM
import java.util.L
import java.util.M
import android.media.AudioM
import android.os.B
import android.annotation.SuppressL
import android.app.ListA
import android.content.I
import android.view.KeyE
import android.view.M
import android.view.MenuI
import android.view.V
import android.view.View.OnClickL
import android.widget.ImageB
import android.widget.ListV
import android.widget.SeekB
import android.widget.SimpleA
import android.widget.T
public class MainActivity extends ListActivity {
public static ImageButton start_
private ImageButton last_
private ImageButton next_
public static SeekBar progressB
private SeekBar volumeB
public static List&Map&String, Object&& mList= new ArrayList&Map&String,Object&&();
public static int currentListItem=0;//当前播放歌曲的索引
@SuppressLint(&SdCardPath&)
public static String MUSIC_PATH = new String(&/mnt/sdcard/Music/&);
public static AudioManager audioManager=
private String[] mFrom=new String[]{&img&,&music_name&};
private int[] mTo=new int[]{R.id.img, R.id.music_name};
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
musicList();
/*初始化Button*/
private void init(){
next_btn= (ImageButton) this.findViewById(R.id.next_btn);
next_btn.setOnClickListener(btnListen);
start_btn = (ImageButton) this.findViewById(R.id.start_btn);
start_btn.setOnClickListener(btnListen);
last_btn= (ImageButton) this.findViewById(R.id.last_btn);
last_btn.setOnClickListener(btnListen);
volumeBar=(SeekBar) this.findViewById(R.id.volume_seekBar);
progressBar =(SeekBar) this.findViewById(R.id.progressBar);
/*进度条监听*/
progressBar.setOnSeekBarChangeListener(new ProgressBarChange());
/*退出后再次进去程序时,进度条保持持续更新*/
if(PlayerService.mediaPlayer!=null){
//设置进度条最大值
MainActivity.progressBar.setMax(PlayerService.mediaPlayer.getDuration());
progressBar.setProgress(PlayerService.mediaPlayer.getCurrentPosition());
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
/* 把当前音量值赋给进度条 */
volumeBar.setProgress(audioManager
.getStreamVolume(AudioManager.STREAM_MUSIC));
/* 监听音量 */
volumeBar.setOnSeekBarChangeListener(new VolumeBarChang());
/*设置按键监听*/
private OnClickListener btnListen = new OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.start_btn:
if(PlayerService.mediaPlayer.isPlaying()){
playMusic(AppConstant.PlayerMag.PAUSE);
start_btn.setImageDrawable(getResources().getDrawable(R.drawable.pause_round));
playMusic(AppConstant.PlayerMag.PLAY);
start_btn.setImageDrawable(getResources().getDrawable(R.drawable.play_round));
case R.id.next_btn:
nextMusic();
case R.id.last_btn:
frontMusic();
/*显示歌曲到listView*/
public void musicList(){
File home= new File(MUSIC_PATH);
File[] files=home.listFiles(new MusicFilter());
Map&String,Object& mMap =
mList.clear();
if(files.length & 0){
for(File f:files){
mMap = new HashMap&String,Object&();
mMap.put(&img&, R.drawable.music_round);
mMap.put(&music_name&, f.getName());
mList.add(mMap);
SimpleAdapter mAdapter = new SimpleAdapter(this, mList, R.layout.item, mFrom, mTo);
setListAdapter(mAdapter);
//播放音乐
public void playMusic(int action){
Intent intent = new Intent();
intent.putExtra(&CMD&, action);
intent.putExtra(&ITEM&, currentListItem);
intent.setClass(MainActivity.this, PlayerService.class);
startService(intent);
public void nextMusic(){
if (++currentListItem &= mList.size()) {
Toast.makeText(MainActivity.this, &已到最后一首歌曲&, Toast.LENGTH_SHORT)
currentListItem = mList.size() - 1;
playMusic(AppConstant.PlayerMag.PLAY);
public void frontMusic(){
if (--currentListItem & 0) {
playMusic(AppConstant.PlayerMag.PLAY);
Toast.makeText(MainActivity.this, &已到第一首歌曲&, Toast.LENGTH_SHORT)
currentListItem = 0;
/* 音乐选择监听
* 用户点击listview的栏目,直接播放
protected void onListItemClick(ListView l, View v, int position, long id) {
currentListItem =
playMusic(AppConstant.PlayerMag.PLAY);
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_BACK){
this.finish();
return super.onKeyDown(keyCode, event);
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.main, menu);
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId() == R.id.exit){
Intent intent = new Intent();
intent.setClass(MainActivity.this, PlayerService.class);
stopService(intent);//停止Service
MainActivity.this.finish();
return super.onOptionsItemSelected(item);
其中进度和音量的实现如下:
package com.example.
import android.widget.SeekB
* 播放进度监听
public class ProgressBarChange implements SeekBar.OnSeekBarChangeListener{
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// 当进度条的值改变时,音乐播放器从新的位置开始播放
if(fromUser){
PlayerService.mediaPlayer.seekTo(progress);
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
PlayerService.mediaPlayer.pause(); // 开始拖动进度条时,音乐暂停播放
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
PlayerService.mediaPlayer.start();// 停止拖动进度条时,音乐开始播放
package com.example.
import android.media.AudioM
import android.widget.SeekB
* 音量监听
public class VolumeBarChang implements SeekBar.OnSeekBarChangeListener{
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
MainActivity.audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress,
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
最后就是service部分的了:
package com.example.
import java.io.IOE
import java.util.M
import android.app.S
import android.content.I
import android.media.MediaP
import android.os.IB
import android.widget.T
public class PlayerService extends Service implements Runnable,
MediaPlayer.OnCompletionListener{
public static MediaPlayer mediaPlayer=
private static boolean isLoop=
private String path =
private int CMD;
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
if(mediaPlayer != null){
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer=
mediaPlayer=new MediaPlayer();
mediaPlayer.setOnCompletionListener(this);
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
CMD=(int)intent.getIntExtra(&CMD&, AppConstant.PlayerMag.PLAY);
if(CMD == AppConstant.PlayerMag.PLAY){
playMusic((int)intent.getIntExtra(&ITEM&,MainActivity.currentListItem));
}else if(CMD == AppConstant.PlayerMag.PAUSE){
if(mediaPlayer.isPlaying()){
mediaPlayer.pause();
mediaPlayer.start();
new Thread(this).start();//进度条开始
return super.onStartCommand(intent, flags, startId);
public void playMusic(int item) {
Map&String, Object& map = MainActivity.mList.get(item);
path=MainActivity.MUSIC_PATH+map.get(&music_name&);
mediaPlayer.reset();
mediaPlayer.setDataSource(path);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.setLooping(isLoop);
MainActivity.progressBar.setMax(PlayerService.mediaPlayer.getDuration());//设置播放进度条的最大值
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if(mediaPlayer != null){
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer=
public void run() {
int currentPosition = 0;// 设置默认进度条当前位置
int total = mediaPlayer.getDuration();//
while (mediaPlayer != null && currentPosition & total) {
Thread.sleep(1000);
if (mediaPlayer != null) {
currentPosition = mediaPlayer.getCurrentPosition();
} catch (InterruptedException e) {
e.printStackTrace();
MainActivity.progressBar.setProgress(currentPosition);
public void onCompletion(MediaPlayer mp) {
/*当前歌曲播放完,自动播放跳到下一首*/
if (++MainActivity.currentListItem &= MainActivity.mList.size()) {
Toast.makeText(PlayerService.this, &已到最后一首歌曲&, Toast.LENGTH_SHORT)
MainActivity.currentListItem--;
MainActivity.progressBar.setMax(0);
playMusic(MainActivity.currentListItem);
MainActivity.start_btn.setImageDrawable(getResources().getDrawable(R.drawable.play_round));
业余时间第一次去做算是比较完整小应用,其中学到真的还是很多的,其中很多是在blog的各大神中学的,
所以自己也要把这次发布出来,希望各位大神级的多多指点下我这种菜鸟。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3583次
排名:千里之外
(1)(5)(1)(7)delphi 中mediaplayer1控件 怎么判断播放完毕?_百度知道
delphi 中mediaplayer1控件 怎么判断播放完毕?
)我是用mediaplayer1播放了一个声音文件.EndPos then
ShowMessage('begin
MediaPlayer1;这个是程序一运行就开始播放怎么才能判断呢,怎么才能判断播放完毕 然后弹出对话框呢;播放完毕
^_^&#39?我这样做 不行啊procedure TForm1.Position=mediaplayer1: TObject).P
if mediaplayer1.FormCreate(Sender
提问者采纳
procedure TForm1:30-----------------------------------------------------------以上是选自魔法师rarnu的答案.FormCreate(S是在窗口创建时被调用的,在程序运行周期内。一般来讲!特此声明。-----------------------------------------------------------利用TMediaPlayer控件的Mode属性就能够判断播放完毕时Mode属性的值为mpStopped回答者,当Form1做为主窗口时,它可能只被调用一次: TObject)你加的位置不对啊:网友专家 rarnu - 魔法师 五级 8-6 15
其他类似问题
为您推荐:
您可能关注的推广
delphi的相关知识
其他1条回答
构造函数的确只能在实例化时调用一次而且调用者(事件源)是Application本身所以你不能在Create事件里判断Mediaplayer的模式应该做一个Timer,然后进行判断楼上的朋友已经找到我以前的答复了,在此表示感谢
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁&&国之画&&&&&&
&& &&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!根据 API 级别筛选:
&&&↳
android.media.MediaPlayer
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 .
Please see
for additional help using MediaPlayer.
Topics covered here are:
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.
From this state diagram, one can see that a MediaPlayer object has the
following states:
When a MediaPlayer object is just created using new or
is called, it is in the Idle and after
is called, it is in the End state. Between these
two states is the life cycle of the MediaPlayer object.
There is a subtle but important difference between a newly constructed
MediaPlayer object and the MediaPlayer object after
is called. It is a programming error to invoke methods such
in the Idle state for both cases. If any of these
methods is called right after a MediaPlayer object is constructed,
the user supplied callback method OnErrorListener.onError() won't be
called by the internal player engine and the object state remains
but if these methods are called right after ,
the user supplied callback method OnErrorListener.onError() will be
invoked by the internal player engine and the object will be
transfered to the Error state.
It is also recommended that once
a MediaPlayer object is no longer being used, call
immediately
so that resources used by the internal player engine associated with the
MediaPlayer object can be released immediately. Resource may include
singleton resources such as hardware acceleration components and
failure to call
may cause subsequent instances of
MediaPlayer objects to fallback to software implementations or fail
altogether. Once the MediaPlayer
object is in the End state, it can no longer be used and
there is no way to bring it back to any other state.
Furthermore,
the MediaPlayer objects created using new is in the
Idle state, while those created with one
of the overloaded convenient create methods are NOT
in the Idle state. In fact, the objects are in the Prepared
state if the creation using create method is successful.
In general, some playback control operation may fail due to various
reasons, such as unsupported audio/video format, poorly interleaved
audio/video, resolution too high, streaming timeout, and the like.
Thus, error reporting and recovery is an important concern under
these circumstances. Sometimes, due to programming errors, invoking a playback
control operation in an invalid state may also occur. Under all these
error conditions, the internal player engine invokes a user supplied
OnErrorListener.onError() method if an OnErrorListener has been
registered beforehand via
It is important to note that once an error occurs, the
MediaPlayer object enters the Error state (except as noted
above), even if an error listener has not been registered by the application.
In order to reuse a MediaPlayer object that is in the
Error state and recover from the error,
can be called to restore the object to its Idle
It is good programming practice to have your application
register a OnErrorListener to look out for error notifications from
the internal player engine.
IllegalStateException is
thrown to prevent programming errors such as calling ,
, or one of the overloaded setDataSource
methods in an invalid state.
transfers a
MediaPlayer object in the Idle state to the
Initialized state.
An IllegalStateException is thrown if
setDataSource() is called in any other state.
It is good programming
practice to always look out for IllegalArgumentException
and IOException that may be thrown from the overloaded
setDataSource methods.
A MediaPlayer object must first enter the Prepared state
before playback can be started.
There are two ways (synchronous vs.
asynchronous) that the Prepared state can be reached:
either a call to
(synchronous) which
transfers the object to the Prepared state once the method call
returns, or a call to
(asynchronous) which
first transfers the object to the Preparing state after the
call returns (which occurs almost right way) while the internal
player engine continues working on the rest of preparation work
until the preparation work completes. When the preparation completes or when
call returns,
the internal player engine then calls a user supplied callback method,
onPrepared() of the OnPreparedListener interface, if an
OnPreparedListener is registered beforehand via .
It is important to note that
the Preparing state is a transient state, and the behavior
of calling any method with side effect while a MediaPlayer object is
in the Preparing state is undefined.
An IllegalStateException is
is called in
any other state.
While in the Prepared state, properties
such as audio/sound volume, screenOnWhilePlaying, looping can be
adjusted by invoking the corresponding set methods.
To start the playback,
must be called. After
returns successfully, the MediaPlayer object is in the
Started state.
can be called to test
whether the MediaPlayer object is in the Started state.
While in the Started state, the internal player engine calls
a user supplied OnBufferingUpdateListener.onBufferingUpdate() callback
method if a OnBufferingUpdateListener has been registered beforehand
This callback allows applications to keep track of the buffering status
while streaming audio/video.
has not effect
on a MediaPlayer object that is already in the Started state.
Playback can be paused and stopped, and the current playback position
can be adjusted. Playback can be paused via . When the call to
returns, the MediaPlayer object enters the
Paused state. Note that the transition from the Started
state to the Paused state and vice versa happens
asynchronously in the player engine. It may take some time before
the state is updated in calls to , and it can be
a number of seconds in the case of streamed content.
to resume playback for a paused
MediaPlayer object, and the resumed playback
position is the same as where it was paused. When the call to
returns, the paused MediaPlayer object goes back to
the Started state.
has no effect on
a MediaPlayer object that is already in the Paused state.
stops playback and causes a
MediaPlayer in the Started, Paused, Prepared
or PlaybackCompleted state to enter the
Stopped state.
Once in the Stopped state, playback cannot be started
are called to set
the MediaPlayer object to the Prepared state again.
has no effect on a MediaPlayer
object that is already in the Stopped state.
The playback position can be adjusted with a call to
Although the asynchronuous
call returns right way, the actual seek operation may take a while to
finish, especially for audio/video being streamed. When the actual
seek operation completes, the internal player engine calls a user
supplied OnSeekComplete.onSeekComplete() if an OnSeekCompleteListener
has been registered beforehand via
can also be called in the other states,
such as Prepared, Paused and PlaybackCompleted
Furthermore, the actual current playback position
can be retrieved with a call to , which
is helpful for applications such as a Music player that need to keep
track of the playback progress.
When the playback reaches the end of stream, the playback completes.
If the looping mode was being set to truewith
, the MediaPlayer object shall remain in
the Started state.
If the looping mode was set to false
, the player engine calls a user supplied callback method,
OnCompletion.onCompletion(), if a OnCompletionListener is registered
beforehand via .
The invoke of the callback signals that the object is now in the
PlaybackCompleted state.
While in the PlaybackCompleted
state, calling
can restart the playback from the
beginning of the audio/video source.
Valid and invalid states
Method Name
Valid Sates
Invalid States
attachAuxEffect
{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}
{Idle, Error}
This method must be called after setDataSource.
Calling it does not change the object state.
getAudioSessionId
This method can be called in any state and calling it does not change
the object state.
getCurrentPosition
{Idle, Initialized, Prepared, Started, Paused, Stopped,
PlaybackCompleted}
Successful invoke of this method in a valid state does not change the
state. Calling this method in an invalid state transfers the object
to the Error state.
getDuration
{Prepared, Started, Paused, Stopped, PlaybackCompleted}
{Idle, Initialized, Error}
Successful invoke of this method in a valid state does not change the
state. Calling this method in an invalid state transfers the object
to the Error state.
getVideoHeight
{Idle, Initialized, Prepared, Started, Paused, Stopped,
PlaybackCompleted}
Successful invoke of this method in a valid state does not change the
state. Calling this method in an invalid state transfers the object
to the Error state.
getVideoWidth
{Idle, Initialized, Prepared, Started, Paused, Stopped,
PlaybackCompleted}
Successful invoke of this method in a valid state does not change
the state. Calling this method in an invalid state transfers the
object to the Error state.
{Idle, Initialized, Prepared, Started, Paused, Stopped,
PlaybackCompleted}
Successful invoke of this method in a valid state does not change
the state. Calling this method in an invalid state transfers the
object to the Error state.
{Started, Paused}
{Idle, Initialized, Prepared, Stopped, PlaybackCompleted, Error}
Successful invoke of this method in a valid state transfers the
object to the Paused state. Calling this method in an
invalid state transfers the object to the Error state.
{Initialized, Stopped}
{Idle, Prepared, Started, Paused, PlaybackCompleted, Error}
Successful invoke of this method in a valid state transfers the
object to the Prepared state. Calling this method in an
invalid state throws an IllegalStateException.
prepareAsync
{Initialized, Stopped}
{Idle, Prepared, Started, Paused, PlaybackCompleted, Error}
Successful invoke of this method in a valid state transfers the
object to the Preparing state. Calling this method in an
invalid state throws an IllegalStateException.
After , the object is no longer available.
{Idle, Initialized, Prepared, Started, Paused, Stopped,
PlaybackCompleted, Error}
After , the object is like being just created.
{Prepared, Started, Paused, PlaybackCompleted}
{Idle, Initialized, Stopped, Error}
Successful invoke of this method in a valid state does not change
the state. Calling this method in an invalid state transfers the
object to the Error state.
setAudioSessionId
{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted,
This method must be called in idle state as the audio session ID must be known before
calling setDataSource. Calling it does not change the object state.
setAudioStreamType
{Idle, Initialized, Stopped, Prepared, Started, Paused,
PlaybackCompleted}
Successful invoke of this method does not change the state. In order for the
target audio stream type to become effective, this method must be called before
prepare() or prepareAsync().
setAuxEffectSendLevel
Calling this method does not change the object state.
setDataSource
{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted,
Successful invoke of this method in a valid state transfers the
object to the Initialized state. Calling this method in an
invalid state throws an IllegalStateException.
setDisplay
This method can be called in any state and calling it does not change
the object state.
setLooping
{Idle, Initialized, Stopped, Prepared, Started, Paused,
PlaybackCompleted}
Successful invoke of this method in a valid state does not change
the state. Calling this method in an
invalid state transfers the object to the Error state.
This method can be called in any state and calling it does not change
the object state.
setOnBufferingUpdateListener
This method can be called in any state and calling it does not change
the object state.
setOnCompletionListener
This method can be called in any state and calling it does not change
the object state.
setOnErrorListener
This method can be called in any state and calling it does not change
the object state.
setOnPreparedListener
This method can be called in any state and calling it does not change
the object state.
setOnSeekCompleteListener
This method can be called in any state and calling it does not change
the object state.
setScreenOnWhilePlaying
This method can be called in any state and calling it does not change
the object state.
{Idle, Initialized, Stopped, Prepared, Started, Paused,
PlaybackCompleted}
Successful invoke of this method does not change the state.
setWakeMode
This method can be called in any state and calling it does not change
the object state.
{Prepared, Started, Paused, PlaybackCompleted}
{Idle, Initialized, Stopped, Error}
Successful invoke of this method in a valid state transfers the
object to the Started state. Calling this method in an
invalid state transfers the object to the Error state.
{Prepared, Started, Stopped, Paused, PlaybackCompleted}
{Idle, Initialized, Error}
Successful invoke of this method in a valid state transfers the
object to the Stopped state. Calling this method in an
invalid state transfers the object to the Error state.
Permissions
One may need to declare a corresponding WAKE_LOCK permission
Interface definition of a callback to be invoked indicating buffering
status of a media resource being streamed over the network.&
Interface definition for a callback to be invoked when playback of
a media source has completed.&
Interface definition of a callback to be invoked when there
has been an error during an asynchronous operation (other errors
will throw exceptions at method call time).&
Interface definition of a callback to be invoked to communicate some
info and/or warning about the media or its playback.&
Interface definition for a callback to be invoked when the media
source is ready for playback.&
Interface definition of a callback to be invoked indicating
the completion of a seek operation.&
Interface definition of a callback to be invoked when the
video size is first known or updated
The video is streamed and its container is not valid for progressive
playback i.e the video's index (e.g moov atom) is not at the start of the
Media server died.
Unspecified media player error.
Bad interleaving means that a media has been improperly interleaved or
not interleaved at all, e.g has all the video samples first then all the
audio ones.
MediaPlayer is resuming playback after filling buffers.
MediaPlayer is temporarily pausing playback internally in order to
buffer more data.
A new set of metadata is available.
The media cannot be seeked (e.g live stream)
Unspecified media player info.
The video is too complex for the decoder: it can't decode frames fast
公有构造函数
Default constructor.
(int effectId)
Attaches an auxiliary effect to the player.
( context,
Convenience method to create a MediaPlayer for a given Uri.
( context, int resid)
Convenience method to create a MediaPlayer for a given resource id.
( context,
Convenience method to create a MediaPlayer for a given Uri.
Returns the audio session ID.
Gets the current playback position.
Gets the duration of the file.
Returns the height of the video.
Returns the width of the video.
Checks whether the MediaPlayer is looping or non-looping.
Checks whether the MediaPlayer is playing.
Pauses playback.
Prepares the player for playback, synchronously.
Prepares the player for playback, asynchronously.
Releases resources associated with this MediaPlayer object.
Resets the MediaPlayer to its uninitialized state.
(int msec)
Seeks to specified time position.
(int sessionId)
Sets the audio session ID.
(int streamtype)
Sets the audio stream type for this MediaPlayer.
(float level)
Sets the send level of the player to the attached auxiliary effect
Sets the data source (file-path or http/rtsp URL) to use.
( fd, long offset, long length)
Sets the data source (FileDescriptor) to use.
Sets the data source (FileDescriptor) to use.
( context,
Sets the data source as a content Uri.
Sets the SurfaceHolder to use for displaying the video portion of the media.
(boolean looping)
Sets the player to be looping or non-looping.
( listener)
Register a callback to be invoked when the status of a network
stream's buffer has changed.
( listener)
Register a callback to be invoked when the end of a media source
has been reached during playback.
( listener)
Register a callback to be invoked when an error has happened
during an asynchronous operation.
( listener)
Register a callback to be invoked when an info/warning is available.
( listener)
Register a callback to be invoked when the media source is ready
for playback.
( listener)
Register a callback to be invoked when a seek operation has been
completed.
( listener)
Register a callback to be invoked when the video size is
known or updated.
(boolean screenOn)
Control whether we should use the attached SurfaceHolder to keep the
screen on while video playback is occurring.
(float leftVolume, float rightVolume)
Sets the volume on this player.
( context, int mode)
Set the low-level power management behavior for this MediaPlayer.
Starts or resumes playback.
Stops playback after playback has been stopped or paused.
Called before the object's memory is reclaimed by the VM.
继承的方法
来自 class
Creates and returns a copy of this Object.
Compares this instance with the specified object and indicates if they
are equal.
Called before the object's memory is reclaimed by the VM.
&?&extends&&
Returns the unique instance of
that represents this
object's class.
Returns an integer hash code for this object.
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
Returns a string containing a concise, human-readable description of this
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK
MEDIA_ERROR_SERVER_DIED
MEDIA_ERROR_UNKNOWN
MEDIA_INFO_BAD_INTERLEAVING
MEDIA_INFO_BUFFERING_END
MEDIA_INFO_BUFFERING_START
MEDIA_INFO_METADATA_UPDATE
MEDIA_INFO_NOT_SEEKABLE
MEDIA_INFO_UNKNOWN
MEDIA_INFO_VIDEO_TRACK_LAGGING
公有构造函数
MediaPlayer
attachAuxEffect
(int effectId)
( context,
( context, int resid)
( context,
getAudioSessionId
getCurrentPosition
getDuration
getVideoHeight
getVideoWidth
prepareAsync
(int msec)
setAudioSessionId
(int sessionId)
setAudioStreamType
(int streamtype)
setAuxEffectSendLevel
(float level)
setDataSource
setDataSource
( fd, long offset, long length)
setDataSource
setDataSource
( context,
setDisplay
setLooping
(boolean looping)
setOnBufferingUpdateListener
( listener)
setOnCompletionListener
( listener)
setOnErrorListener
( listener)
setOnInfoListener
( listener)
setOnPreparedListener
( listener)
setOnSeekCompleteListener
( listener)
setOnVideoSizeChangedListener
( listener)
setScreenOnWhilePlaying
(boolean screenOn)
(float leftVolume, float rightVolume)
setWakeMode
( context, int mode)

我要回帖

更多关于 media player 12 的文章

 

随机推荐