preface
Recent use of native MediaPlayer can not solve a variety of problems so find a third party excellent framework recommended audio framework StarrySky pro test effect is excellent is satisfactory effect!
StarrySky Audio framework
Project dependencies need to be configured with download dependencies in your project’s build.gradle
/ / music plugin maven {url "https://dl.bintray.com/lizixian/StarrySky/"}Copy the code
Need to build. Gradle in app
// Audio implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.lzx:StarrySkyX:2.5.9'Copy the code
The first step
You need to initialize the control in BaseApplication
@Override public void onCreate() { super.onCreate(); / / memory leak detection / / if (LeakCanary. IsInAnalyzerProcess (this)) {/ / return; // } // LeakCanary.install(this); // Initialize the music player starrysky.init (this).apply(); initX5(); }Copy the code
The second step
Use players in your code
/ / prepare StarrySky. With (). Prepare (); // Start playing starrysky.with ().playmusicByurl (mwangyiyunbean.getmp3_url ()); // Pause starrysky.with ().pausemusic ();Copy the code
The PlayerControl class API:
Call starrysky.with () No. API Function No. API Function 1 playMusicById Plays according to songId. 31 getNowPlayingSongUrl Obtains the URL of the currently played song PlayMusicByUrl Plays based on songUrl. 32 getNowPlayingIndex Obtains the subscript of the current played song. 3 playMusicByInfo Plays based on SongInfo Get cache position in milliseconds 4 playMusic, Pass in the playlist and subscript 34 getPlayingPosition gets the play position in milliseconds 5 addInterceptor Adds an interceptor 35 isSkipToNextEnabled whether there is a next track 6 pauseMusic pause 36 IsSkipToPreviousEnabled Whether a previous song is played. 7 restoreMusic Resumes playing after being paused. 37 getPlaybackSpeed Obtains the playing speed 9 Prepare for play, 39 isPaused whether to suspend 11 prepareById Prepare according to songId 40 isIdea is idle 12 prepareByUrl Prepare according to songUrl 41 isBuffering Whether the buffer 13 prepareByInfo prepared from SongInfo 42 isCurrMusicIsPlayingMusic whether incoming music is the next 43 14 skipToNext is playing music IsCurrMusicIsPlaying Determines whether the incoming music is playing 15 skipToPrevious 44 isCurrMusicIsPaused Determines whether the incoming music is paused 16 fastForward adds each tune Speed times 45 isCurrMusicIsIdea Checks whether the incoming music is free. 17 Rewind Fast rewind Decreases the speed times with each tune. 46 isCurrMusicIsBuffering Checks whether the incoming music is buffered OnDerailleur set any times the speed 47 setVolume set the volume, Range: 0 to 1 19 seekTo Move to a new position in the media stream, in milliseconds 48 getVolume Obtains the volume 20 setRepeatMode Sets the playback mode 49 getDuration Obtains the media duration, 21 getRepeatMode Obtains the playback mode. 50 getAudioSessionId Obtains AudioSessionId. 22 getPlayList Obtains the playlist Scan local media information. 23 updatePlayList updates the playlist. 52 cacheSwitch cacheSwitch, You can control whether to use the cache function. 24 addPlayList Adds more playlists. 53 stopByTimedOff Periodically pauses or stops playlists AddSongInfo add a song, specify the location of 55 removePlayerEventListener delete a state monitoring 56 clearPlayerEventListener 27 removeSongInfo delete songs Delete all status listeners. 28 clearPlayList Clears the playlist. 57 focusStateChange focus change listener,LiveData mode 29 getNowPlayingSongInfo Obtains the current song information PlaybackState state monitoring, 30 getNowPlayingSongId LiveData way gets the current playback songs songId 59 setOnPlayProgressListener monitored 60 set schedule SkipMediaQueue Skips the playback queue. 61 setWithOutCallback Requires a status callback. 62 updateCurrIndex Updates the subscript based on the current playback information.
StarrySky summary
StarrySky is an audio integration library. In some projects, if you need to integrate audio playback functions, you need to encapsulate the player, encapsulate the playback control, encapsulate the API and other operations. In fact, these operations are similar in different projects. So StarrySky is a library that integrates the actions needed to play audio.
StarrySky features simple integration, compact, easy to read code, strong scalability, and easy to use. StarrySky has been used by myself and many other developers in real projects, and it has been proven that StarrySky can be used flexibly to handle complex scenarios in projects.