PlayWidget
介绍:
一个音乐播放控件,逼真的留声机效果。
运行效果:
使用说明:
依赖
dependencies {
compile 'com.cleveroad:play-widget:1.0.0'
}
在布局文件中使用 PlayLayout
<com.cleveroad.play_widget.PlayLayout
android:id="@+id/playLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:pa_progress_line_enabled="true"
app:pa_buttons_size="48dp"
app:pa_image_src="@drawable/pa_image"
app:pa_progress_ball_color="#01999933"
app:pa_progress_complete_line_color="#77FFFFFF"
app:pa_progress_line_color="#34FF0000"
app:pa_progress_ball_radius="4dp"
app:pa_progress_complete_line_stroke_width="5dp"
app:pa_progress_line_stroke_width="3dp"
app:pa_progress_line_padding="10dp"
app:pa_diffusers_padding="15dp"
app:pa_big_diffuser_shadow_width="30dp"
app:pa_medium_diffuser_shadow_width="25dp"
app:pa_small_diffuser_shadow_width="20dp"
app:pa_big_diffuser_color="#009933"
app:pa_medium_diffuser_color="#003399"
app:pa_play_button_background_tint="#123456"
/>
或者代码中
mPlayLayout = new PlayLayout.Builder(context)
.setLayoutParams(params)
.setBigDiffuserColorResource(R.color.test_blue)
.setMediumDiffuserColorResource(R.color.test_green)
.setBigDiffuserShadowWidthResource(R.dimen.test_dimen_10)
.setMediumDiffuserShadowWidthResource(R.dimen.test_dimen_10)
.setSmallDiffuserShadowWidthResource(R.dimen.test_dimen_10)
.setProgressLinePaddingResource(R.dimen.test_dimen_10)
.setProgressBallRadiusResource(R.dimen.test_dimen_20)
.setProgressCompleteLineStrokeWidthResource(R.dimen.test_dimen_10)
.setProgressLineStrokeWidthResource(R.dimen.test_dimen_20)
.setProgressLineColorResource(R.color.test_blue)
.setProgressCompleteColorResource(R.color.test_green)
.setProgressBallColorResource(R.color.test_red)
.setDiffusersPaddingResource(R.dimen.test_dimen_30)
.setButtonsSizeResource(R.dimen.test_dimen_30)
.setPlayButtonBackgroundTintList(colorStateList)
.setImageResource(R.drawable.imgpsh_fullsize_hd)
.build();
container.addView(playLayout);
改变设置的方法,这些方法中的属性都可以通过xml设置:
void setProgressEnabled(boolean enabled)
void setButtonsSize(int buttonsSize)
void setImageBitmap(Bitmap bm)
void setImageURI(@Nullable Uri uri)
void setImageDrawable(@Nullable Drawable drawable)
void setImageResource(@DrawableRes int resId)
void setProgressBallColor(int progressBallColor)
void setProgressCompleteColor(int progressCompleteColor)
void setProgressLineColor(int progressLineColor)
void setProgressBallRadius(float radius)
void setProgressCompleteLineStrokeWidth(float progressCompleteLineStrokeWidth)
void setProgressLineStrokeWidth(float progressLineStrokeWidth)
void setProgressLinePadding(int padding)
void setDiffusersPadding(int padding)
void setBigDiffuserShadowWidth(int bigDiffuserShadowWidth)
void setMediumDiffuserShadowWidth(int mediumDiffuserShadowWidth)
void setSmallDiffuserShadowWidth(int smallDiffuserShadowWidth)
void setBigDiffuserColor(int color)
void setMediumDiffuserColor(int color)
void setPlayButtonBackgroundTintList(@Nullable ColorStateList tint)
检查是否打开:
boolean isOpen();
设置进度 (0.0f - 1.0f):
void setProgress(float progress)
监听按钮事件:
void setOnButtonsClickListener(new OnButtonsClickListener() {
@Override
public void onShuffleClicked() { }
@Override
public void onSkipPreviousClicked() { }
@Override
public void onSkipNextClicked() { }
@Override
public void onRepeatClicked() { }
@Override
public void onPlayButtonClicked() { }
});
void setOnButtonsLongClickListener(new OnButtonsLongClickListener() {
@Override
public void onShuffleLongClicked() {}
@Override
public void onSkipPreviousLongClicked() {}
@Override
public void onSkipNextLongClicked() {}
@Override
public void onRepeatLongClicked() {}
@Override
public void onPlayButtonLongClicked() {}
});
监听进度变化:
void setOnProgressChangedListener(new OnProgressChangedListener() {
@Override
void onPreSetProgress();
@Override
public void onProgressChanged(float progress) {}
});
onPreSetProgress方法将在用户触摸进度条改变进度的时候被调用。要改变阴影参数使用方法:
void shadowChanged(
float bigDiffuserShadowPercentage,
float mediumDiffuserShadowPercentage,
float smallDiffuserShadowPercentage
);
你可以使用shadow provider VisualizerShadowChanger。VisualizerShadowChanger收听系统音频并翻译为扩散器阴影变化。要实现你自己的 shadow provider,,只需继承ShadowPercentageProvider类。使用changeShadow方法设置新的 shadow percentages
protected void changeShadow(
float bigDiffuserShadowPercentage,
float mediumDiffuserShadowPercentage,
float smallDiffuserShadowPercentage
)
设置阴影:
mPlayLayout.setShadowProvider( VisualizerShadowChanger.newInstance(yourAudioSessionId) );
where yourAudioSessionId
is audioSession from MediaPlayer or AudioTrack or 0. For using VisualizerShadowChanger need to provide permissions:
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
已下载
0