项目作者: henryblue

项目描述 :
A simple custom music play widget
高级语言: Java
项目地址: git://github.com/henryblue/MiniMusicView.git
创建时间: 2016-08-15T04:50:06Z
项目社区:https://github.com/henryblue/MiniMusicView

开源协议:Apache License 2.0

下载


MiniMusicView

A music player widget to add custom layout.

ScreenShot





Usage

First you can add gradle dependency with command :

  1. dependencies {
  2. ......
  3. compile 'com.henryblue.minimusicview:library:1.0.1'
  4. }

To add gradle dependency you need to open build.gradle (in your app folder,not in a project folder) then copy and add the dependencies there in the dependencies block;

Use default layout

1.Add MiniMusicView in your layout

  1. <com.hrb.library.MiniMusicView
  2. android:id="@+id/mmv_music"
  3. app:isLoadLayout="true"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent" ></com.hrb.library.MiniMusicView>

2.set music url and play music

  1. mMusicView = (MiniMusicView) findViewById(R.id.mmv_music);
  2. mMusicView.setTitleText("music name");
  3. mMusicView.setAuthor("singer name");
  4. mMusicView.startPlayMusic("music url");
  5. // Or through the new way to create view object
  6. // mMusicView = new MiniMusicView(this);
  7. // mMusicView.initDefaultView();
  8. // mMusicView.setTitleText("music name");
  9. // mMusicView.startPlayMusic("music url");

3.stop play music

  1. @Override
  2. protected void onDestroy() {
  3. mMusicView.stopPlayMusic();
  4. super.onDestroy();
  5. }

Achieve the effect of the first picture above.

Use custom layout

1.Add MiniMusicView in your layout

  1. <com.hrb.library.MiniMusicView
  2. android:id="@+id/mmv_music"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent" ></com.hrb.library.MiniMusicView>

2.set layout, music url and play music

  1. mMusicView = (MiniMusicView) findViewById(R.id.mmv_music);
  2. View view = View.inflate(CustomActivity.this, R.layout.layout_custom_music, null);
  3. TextView title = (TextView) view.findViewById(R.id.tv_music_play_title);
  4. title.setText("music name");
  5. mMusicView.addView(view);
  6. mMusicView.startPlayMusic("music url");
  7. // Or through the new way to create view object
  8. // mMusicView = new MiniMusicView(this);
  9. // mMusicView.addView(view);
  10. // mMusicView.startPlayMusic("music url");

3.you can also set MiniMusicView listener

  1. mMusicView.setOnMusicStateListener(new MiniMusicView.OnMusicStateListener() {
  2. @Override
  3. public void onPrepared(int duration) {
  4. Log.i(TAG, "start prepare play music");
  5. }
  6. @Override
  7. public void onError() {
  8. Log.i(TAG, "start play music error");
  9. }
  10. @Override
  11. public void onInfo(int what, int extra) {
  12. Log.i(TAG, "start play_mini_music music info");
  13. }
  14. @Override
  15. public void onMusicPlayComplete() {
  16. Log.i(TAG, "start play music completed");
  17. }
  18. @Override
  19. public void onSeekComplete() {
  20. Log.i(TAG, "seek play music completed");
  21. }
  22. @Override
  23. public void onProgressUpdate(int duration, int currentPos) {
  24. Log.i(TAG, "play music progress update");
  25. }
  26. @Override
  27. public void onHeadsetPullOut() {
  28. Log.i(TAG, "headset pull out");
  29. }
  30. });

License

  1. Copyright 2016 henryblue
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.