MusicLibrary
一个丰富的音乐播放封装库,针对快速集成音频播放功能,你值得拥有。
Features
- Easily play local and web audio.
- Implement audio services based on IPC, reduce app memory peaks, and avoid OOM.
- Integrating and calling APIs is very simple, and audio functions can be integrated in almost one sentence.
- Provides rich API methods to easily implement various functions.
- In one sentence, you can customize the notification bar and the system notification bar to customize the control of the notification bar.
- Integrated MediaPlayer and ExoPlayer Players, Freely Switchable
- Supports multiple audio formats and supports audio streaming(DASH, SmoothStreaming, HLS,rtmp.).
- Supports the playback progress
- Supports Cache while playing,no network can play.
- Supports changing the playing speed and changing the playing pitch.
Version update record
See details Version update record
project status
The project is basically stable and has been practically used in a number of commercial projects. The current status is to repair the bugs found and to satisfy the requirements raised in the issues. If you encounter any problems in use, welcome feedback.
Demo
Specific application Demo Please refer to NiceMusic
Usage
1.Import library
allprojects {
repositories {
maven{url 'https://dl.bintray.com/lizixian/MusicLibrary'}
}
}
dependencies {
implementation 'com.lzx:MusicLibrary:1.3.8'
}
If your appcompat-v7 package is using 27+, then you need an extra reference to support-media-compat. For example:
implementation 'com.android.support:support-media-compat:27.1.1'
- add MusicLibrary to your Application
public class NiceMusicApplication extends Application {
@Override
public void onCreate() {
if (BaseUtil.getCurProcessName(this).equals("your package name")) {
MusicLibrary musicLibrary = new MusicLibrary.Builder(this)
.build();
musicLibrary.init();
}
}
}
note
- Because the music service is running in the musicLibrary process, in the multi-process case, Application will create multiple times, so you need to add the above judgment in the initialization, initialized in your main process.
- There are some parameters that can be configured during initialization:
- setAutoPlayNext(boolean autoPlayNext) Whether to play the next song automatically after playing the current song
- setUseMediaPlayer(boolean isUseMediaPlayer) Whether to use MediaPlayer
- setNotificationCreater(NotificationCreater creater) Notification bar configuration
- setCacheConfig(cacheConfig) Cache when playing configuration
- giveUpAudioFocusManager() Give up audio focus management, after give up, multiple audio will be mixed together
other instructions If you use the System.exit(0); method to exit the APP, you may need to call the ActivityManager#killBackgroundProcesses method again. Kill the audio process, otherwise it may report a crash, so try not to do it.
- Simple to use (play a song):
SongInfo songInfo = new SongInfo();
songInfo.setSongId("your song Id");
songInfo.setSongUrl("your song url");
MusicManager.get().playMusicByInfo(songInfo);
At least set songId and songUrl to play.To play audio in the local audio or assets folder, or streaming audio such as m3u8, just use set the songUrl and songId as usual.
Wiki
-
MusicLibrary Model
See details MusicLibrary Model Description
-
MusicManager API
See details API Description
-
Notification bar integration
See details Notification Description
-
Cache when playing configuration instructions
See details Cache when playing Description
-
Code implementation and principle
See details Code implementation and principle
PS:
- If you have ideas or opinions and suggestions, please feel free to ask for an issue and like to have a star. Welcome everybody to give pointers.
About me
An android developer in GuangZhou
简书:http://www.jianshu.com/users/286f9ad9c417/latest_articles
Email:386707112@qq.com
If you want to make friends with me, You can give me a Email and follow me。
License
MIT License
Copyright (c) [2018] [lizixian]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.