@ -0,0 +1,9 @@
|
||||
package com.example.musicplayer.constant;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
public class BaseUri {
|
||||
public static String SINGER_URL="http://music.163.com/api/search/get/";
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.example.musicplayer.contract;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
public interface IPlayContract {
|
||||
interface Model{
|
||||
void getSingerImg(String singer);//网络请求获得歌手uri
|
||||
}
|
||||
interface View{
|
||||
String getSingerName(); //得到歌手的姓名
|
||||
void setSingerImg(String ImgUrl); //将图片设置成背景
|
||||
void setImgFail(String errorMessage);
|
||||
}
|
||||
interface Presenter{
|
||||
void getSingerImg(String singer);
|
||||
void getSingerImgSuccess(String ImgUrl); //成功获取图片
|
||||
void getSingerImgFail(); //请求失败
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package com.example.musicplayer.entiy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
public class SingerImg {
|
||||
|
||||
/**
|
||||
* result : {"artistCount":1,"artists":[{"id":840134,"name":"刘瑞琦","picUrl":"http://p1.music.126.net/qTDkcmWPMK3U54RNC0IgMw==/109951163288035254.jpg","alias":[],"albumSize":20,"picId":109951163288035254,"img1v1Url":"http://p1.music.126.net/a13xmSNqxMY5M_R1OFvPvA==/109951163288038157.jpg","accountId":3788031,"img1v1":109951163288038157,"mvSize":16,"followed":false,"trans":null}]}
|
||||
* code : 200
|
||||
*/
|
||||
|
||||
private ResultBean result;
|
||||
private int code;
|
||||
|
||||
public ResultBean getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ResultBean result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static class ResultBean {
|
||||
/**
|
||||
* artistCount : 1
|
||||
* artists : [{"id":840134,"name":"刘瑞琦","picUrl":"http://p1.music.126.net/qTDkcmWPMK3U54RNC0IgMw==/109951163288035254.jpg","alias":[],"albumSize":20,"picId":109951163288035254,"img1v1Url":"http://p1.music.126.net/a13xmSNqxMY5M_R1OFvPvA==/109951163288038157.jpg","accountId":3788031,"img1v1":109951163288038157,"mvSize":16,"followed":false,"trans":null}]
|
||||
*/
|
||||
|
||||
private List<ArtistsBean> artists;
|
||||
|
||||
public List<ArtistsBean> getArtists() {
|
||||
return artists;
|
||||
}
|
||||
|
||||
public void setArtists(List<ArtistsBean> artists) {
|
||||
this.artists = artists;
|
||||
}
|
||||
|
||||
public static class ArtistsBean {
|
||||
/**
|
||||
* id : 840134
|
||||
* name : 刘瑞琦
|
||||
* picUrl : http://p1.music.126.net/qTDkcmWPMK3U54RNC0IgMw==/109951163288035254.jpg
|
||||
* alias : []
|
||||
* albumSize : 20
|
||||
* picId : 109951163288035254
|
||||
* img1v1Url : http://p1.music.126.net/a13xmSNqxMY5M_R1OFvPvA==/109951163288038157.jpg
|
||||
* accountId : 3788031
|
||||
* img1v1 : 109951163288038157
|
||||
* mvSize : 16
|
||||
* followed : false
|
||||
* trans : null
|
||||
*/
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String picUrl;
|
||||
private String img1v1Url;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPicUrl() {
|
||||
return picUrl;
|
||||
}
|
||||
|
||||
public void setPicUrl(String picUrl) {
|
||||
this.picUrl = picUrl;
|
||||
}
|
||||
|
||||
public String getImg1v1Url() {
|
||||
return img1v1Url;
|
||||
}
|
||||
|
||||
public void setImg1v1Url(String img1v1Url) {
|
||||
this.img1v1Url = img1v1Url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.example.musicplayer.https;
|
||||
|
||||
import com.example.musicplayer.constant.BaseUri;
|
||||
import com.example.musicplayer.https.api.SingerImgApi;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.CallAdapter;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
import static com.example.musicplayer.constant.BaseUri.SINGER_URL;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
public class NetWork {
|
||||
private static okhttp3.OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(20, TimeUnit.SECONDS);
|
||||
private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
|
||||
private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();
|
||||
private static SingerImgApi singerImgApi;
|
||||
|
||||
public static SingerImgApi getSingerImgApi(){
|
||||
if(singerImgApi==null){
|
||||
Retrofit retrofit=new Retrofit.Builder()
|
||||
.client(builder.build())
|
||||
.baseUrl(SINGER_URL)
|
||||
.addCallAdapterFactory(rxJavaCallAdapterFactory)
|
||||
.addConverterFactory(gsonConverterFactory)
|
||||
.build();
|
||||
singerImgApi=retrofit.create(SingerImgApi.class);
|
||||
}
|
||||
return singerImgApi;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.example.musicplayer.https;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
public class RetrofitHelp {
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.example.musicplayer.https.api;
|
||||
|
||||
import com.example.musicplayer.entiy.SingerImg;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
public interface SingerImgApi {
|
||||
@POST("web?csrf_token=&type=100")
|
||||
@FormUrlEncoded
|
||||
Observable<SingerImg> getSingerImg(@Field("s")String singer);
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.example.musicplayer.model;
|
||||
|
||||
import android.support.annotation.MainThread;
|
||||
import android.util.Log;
|
||||
|
||||
import com.example.musicplayer.contract.IPlayContract;
|
||||
import com.example.musicplayer.entiy.SingerImg;
|
||||
import com.example.musicplayer.https.NetWork;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
public class IPlayModel implements IPlayContract.Model {
|
||||
private String TAG="IPlayModel";
|
||||
|
||||
private IPlayContract.Presenter mPresenter;
|
||||
|
||||
public IPlayModel(IPlayContract.Presenter presenter){
|
||||
mPresenter=presenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSingerImg(String singer) {
|
||||
NetWork.getSingerImgApi()
|
||||
.getSingerImg(singer)
|
||||
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<SingerImg>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(SingerImg value) {
|
||||
if(value.getCode()==200) {
|
||||
mPresenter.getSingerImgSuccess(value.getResult().getArtists().get(0).getImg1v1Url());
|
||||
Log.d(TAG, "onNext: "+value.getResult().getArtists().get(0).getImg1v1Url());
|
||||
}else{
|
||||
Log.d(TAG, "onNext: "+value.getCode());
|
||||
mPresenter.getSingerImgFail();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
e.printStackTrace();
|
||||
mPresenter.getSingerImgFail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.example.musicplayer.presenter;
|
||||
|
||||
import com.example.musicplayer.base.BasePresenter;
|
||||
import com.example.musicplayer.contract.IPlayContract;
|
||||
import com.example.musicplayer.model.IPlayModel;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
public class PlayPresenter extends BasePresenter<IPlayContract.View> implements IPlayContract.Presenter {
|
||||
private IPlayModel mModel;
|
||||
|
||||
public PlayPresenter(){
|
||||
mModel=new IPlayModel(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getSingerImg(String singer) {
|
||||
mModel.getSingerImg(singer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSingerImgSuccess(String ImgUrl) {
|
||||
if(isAttachView()){
|
||||
getMvpView().setSingerImg(ImgUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSingerImgFail() {
|
||||
if(isAttachView()){
|
||||
getMvpView().setImgFail("获取歌手照片失败");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.example.musicplayer.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/10/26.
|
||||
*/
|
||||
|
||||
//通用的工具类
|
||||
public class CommonUtil {
|
||||
private static Toast toast;
|
||||
|
||||
public static void hideStatusBar(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= 22) {
|
||||
View decorView = activity.getWindow().getDecorView();
|
||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public static void showToast(Context context, String message) {
|
||||
if (toast == null) {
|
||||
toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
|
||||
} else {
|
||||
toast.setText(message);
|
||||
}
|
||||
toast.show();
|
||||
}
|
||||
|
||||
/*
|
||||
* 得到屏幕的宽度
|
||||
|
||||
*/
|
||||
|
||||
public static int getScreenWidth(Context context) {
|
||||
if (null == context) {
|
||||
return 0;
|
||||
}
|
||||
return context.getResources().getDisplayMetrics().widthPixels;
|
||||
}
|
||||
/**
|
||||
* 得到屏幕的高度
|
||||
*/
|
||||
|
||||
public static int getScreenHeight(Context context) {
|
||||
if (null == context) {
|
||||
return 0;
|
||||
}
|
||||
return context.getResources().getDisplayMetrics().heightPixels;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package com.example.musicplayer.view;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.transition.Slide;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.example.musicplayer.R;
|
||||
import com.example.musicplayer.base.BaseActivity;
|
||||
import com.example.musicplayer.contract.IPlayContract;
|
||||
import com.example.musicplayer.entiy.Song;
|
||||
import com.example.musicplayer.presenter.PlayPresenter;
|
||||
import com.example.musicplayer.util.CommonUtil;
|
||||
import com.example.musicplayer.util.FileHelper;
|
||||
|
||||
/**
|
||||
* 播放界面
|
||||
*/
|
||||
public class PlayActivity extends BaseActivity implements IPlayContract.View {
|
||||
|
||||
private String TAG = "PlayActivity";
|
||||
|
||||
private Button mPlayBtn;
|
||||
private Button mLastBtn;
|
||||
private Button mNextBtn;
|
||||
private RelativeLayout mPlayRelative;
|
||||
private PlayPresenter mPresenter;
|
||||
private boolean isPlaying;
|
||||
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
CommonUtil.hideStatusBar(this);
|
||||
setContentView(R.layout.activity_play);
|
||||
|
||||
//设置进入退出动画
|
||||
getWindow().setEnterTransition(new Slide());
|
||||
getWindow().setExitTransition(new Slide());
|
||||
|
||||
//与Presenter建立关系
|
||||
mPresenter = new PlayPresenter();
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.getSingerImg(getSingerName());
|
||||
//
|
||||
mPlayRelative = findViewById(R.id.relative_play);
|
||||
mPlayBtn = findViewById(R.id.btn_player);
|
||||
mLastBtn = findViewById(R.id.btn_last);
|
||||
mNextBtn = findViewById(R.id.next);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
mPlayBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isPlaying = !isPlaying;
|
||||
mPlayBtn.setSelected(isPlaying);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSingerName() {
|
||||
Song song = FileHelper.getSong();
|
||||
Log.d(TAG, "getSingerName: " + "-" + song.getArtist().toString() + "-");
|
||||
return song.getArtist().toString().trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSingerImg(String ImgUrl) {
|
||||
Log.d(TAG, "setSingerImg: success");
|
||||
SimpleTarget<Drawable> simpleTarget = new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
|
||||
mPlayRelative.setBackground(resource);
|
||||
}
|
||||
};
|
||||
|
||||
Glide.with(this)
|
||||
|
||||
.load(ImgUrl)
|
||||
.apply(RequestOptions.placeholderOf(R.drawable.background))
|
||||
.apply(RequestOptions.errorOf(R.drawable.background))
|
||||
.into(simpleTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImgFail(String errorMessage) {
|
||||
CommonUtil.showToast(this, errorMessage);
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.1 KiB |
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="true" android:drawable="@drawable/activity_play_stop"/>
|
||||
<item android:drawable="@drawable/activity_play_start"/>
|
||||
|
||||
</selector>
|
@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/relative_play"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/background"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relative_song"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/actionBarSize">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_back"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@drawable/back" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginStart="5dp"
|
||||
android:text="青茫"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_artist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/relative_song"
|
||||
android:gravity="center"
|
||||
android:text="白敬亭、李宏毅、丁冠森、赵文龙"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="350dp"
|
||||
android:layout_below="@+id/tv_artist">
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relative_music_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@+id/relative_control"
|
||||
android:layout_below="@+id/linear"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginTop="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_current_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="01:34"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/musicSeekBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_toEndOf="@id/tv_current_time"
|
||||
android:layout_toStartOf="@+id/tvTotalTime"
|
||||
android:paddingEnd="15dp"
|
||||
android:paddingStart="15dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTotalTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="05:34"
|
||||
android:textColor="@color/white" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relative_control"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginBottom="40dp">
|
||||
<Button
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:background="@drawable/playstatus_order"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="20dp"/>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_control"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingRight="20dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_last"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="@drawable/activity_play_last" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_player"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:background="@drawable/selector_activity_play" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/next"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="@drawable/activity_play_next" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|