media player classic,Media Player Classic,经典多媒体播放器的全面解析

admin 2 2026-11-12 22:30:06

The MediaPlayer class is a core component in many programming frameworks for handling audio and video playback. Here's an overview across major platforms:

Android (android.media.MediaPlayer)

The most well-known MediaPlayer class. Key features:

Common methods:

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(path);        // Set audio/video source
mp.prepare();                  // Prepare (sync)
mp.prepareAsync();             // Prepare (async)
mp.start();                    // Start playback
mp.pause();                    // Pause
mp.stop();                     // Stop
mp.seekTo(milliseconds);       // Seek
mp.release();                  // Release resources

State machine: MediaPlayer follows a strict lifecycle (Idle → Initialized → Prepared → Started → Paused → Stopped → Released). Calling methods in the wrong state throws IllegalStateException.

media player classic

Callbacks:

  • setOnPreparedListener()
  • setOnCompletionListener()
  • setOnErrorListener()
  • setOnBufferingUpdateListener()

Best practice: Always call release() when done, and use prepareAsync() for network streams to avoid blocking the UI thread.


JavaFX (javafx.scene.media.MediaPlayer)

Media media = new Media("file:///path/to/file.mp3");
MediaPlayer player = new MediaPlayer(media);
player.play();
player.pause();
player.seek(Duration.seconds(30));
player.setVolume(0.5);

Supports status properties (PLAYING, PAUSED, STOPPED) and listeners via setOnEndOfMedia() etc.

media player classic


Windows Media Foundation / UWP (Windows.Media.Playback.MediaPlayer)

var player = new MediaPlayer();
player.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///video.mp4"));
player.Play();

Uses MediaSource, supports MediaPlaybackSession for low-level control, and integrates with MediaPlayerElement for UI.


.NET / WPF (System.Windows.Media.MediaPlayer)

MediaPlayer player = new MediaPlayer();
player.Open(new Uri("sound.mp3", UriKind.Relative));
player.Play();
player.MediaEnded += (s, e) => { /* handle end */ };

Lightweight, but limited compared to MediaElement.


Which one are you asking about?

Let me know the platform/framework (Android, JavaFX, WPF, UWP, etc.) and I can give you:

  • Full method reference
  • Code examples for a specific use case (streaming, background playback, playlist)
  • Common pitfalls and lifecycle handling

上一篇:qq麻将看牌器,QQ麻将看牌器
下一篇:(axis升级axis2)" axis2
相关文章

 发表评论

暂时没有评论,来抢沙发吧~