FMDetailActivity.java 22.4 KB
Newer Older
徐健 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
package com.yidianling.fm;

import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.ydl.media.audio.AudioPlayer;
import com.ydl.media.audio.OnPlayerEventListener;
import com.ydl.media.audio.model.Music;
import com.ydl.media.view.PlayerFloatHelper;
import com.ydl.ydl_image.module.GlideApp;
import com.ydl.ydl_image.transform.GlideCircleRingTransform;
import com.ydl.ydlcommon.base.BaseActivity;
import com.ydl.ydlcommon.data.http.RxUtils;
import com.ydl.ydlcommon.data.http.ThrowableConsumer;
import com.ydl.ydlcommon.utils.remind.ToastHelper;
import com.ydl.ydlcommon.view.TitleBar;
import com.ydl.ydlcommon.view.dialog.YDLShareDialog;
import com.yidianling.common.tools.LogUtil;
import com.yidianling.common.tools.RxDeviceTool;
import com.yidianling.common.tools.RxImageTool;
import com.yidianling.fm.param.DetailParam;
import com.yidianling.fm.param.FavParam;
import com.yidianling.fm.response.FMDetail;
import com.yidianling.fm.router.FMIn;
import com.yidianling.fm.widget.FMSurfaceView;
45
import com.yidianling.user.api.event.UserLoginEvent;
徐健 committed
46 47 48 49 50 51 52 53 54 55

import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

56
import de.greenrobot.event.EventBus;
徐健 committed
57 58 59 60 61 62 63
import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * 电台详情
 * Created by softrice on 15/12/11.
 */
@Route(path = "/fm/detail")
konghaorui committed
64
public class FMDetailActivity extends BaseActivity implements View.OnClickListener, OnPlayerEventListener{
徐健 committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159

    int id;
    boolean isSplash;

    TitleBar tb_title;
    ImageView iv_play;
    TextView tv_fm_title;
    TextView tv_anchor;
    TextView tv_like;
    TextView tv_listen;
    ImageView iv_love;
    ImageView iv_next;
    ImageView iv_last;
    ImageView iv_share;
    LinearLayout ll_bottom;
    TextView tv_currentTime;
    TextView tv_allTime;
    SeekBar fm_progress;
    FMSurfaceView fmSurfaceView;
    LinearLayout ll_last_time;
    ImageView fm_img;
    ImageView refresh_icon;
    CardView fm_card;

    ImageView tv_like_icon;
    ImageView tv_listen_icon;

    private ValueAnimator anim;

    private ArrayList<Integer> fmIdList = new ArrayList();

    private FMDetail fmDetail;
    private SimpleDateFormat formatter = new SimpleDateFormat("mm:ss");
    private Date currentTime = new Date();

    private boolean canNext = true;

    private int time;
    private int allTime;
    private int max_progress = 1000;
//    private MyPlayer player;

    private static final String ID = "id";
    private static final String IS_SPLASH = "isSplash";
    //是否跳转到心事动态
    private boolean isToTrend = false;

    public static Intent newIntent(Activity activity, int id) {
        Intent intent = new Intent(activity, FMDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(ID, id);
        intent.putExtra("bundle", bundle);
        return intent;
    }

    public static Intent newIntent(Activity activity, int id, boolean isSplash) {
        Intent intent = new Intent(activity, FMDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(ID, id);
        bundle.putBoolean(IS_SPLASH, isSplash);
        intent.putExtra("bundle", bundle);
        return intent;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        if (null == intent) {
            finish();
            return;
        }
        Bundle bundle = intent.getBundleExtra("bundle");
        if (null != bundle) {
            id = bundle.getInt(ID, 0);
            isSplash = bundle.getBoolean("isSplash", false);
        }
        //路由跳转 取值
        if (intent.hasExtra("routerParam")) {
            String json = intent.getStringExtra("routerParam");
            if (!TextUtils.isEmpty(json)) {
                try {
                    JSONObject jsonObject = new JSONObject(json);
                    id = jsonObject.getInt("id");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

        //重置当前为第一首
        fmIdList.clear();
        getFMDetail(id, true);
    }

    @Override
    protected int layoutResId() {
160
        return R.layout.fm_activity_fm_detail;
徐健 committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    }

    /**
     * 路由跳转 取值
     */
    private void getParam() {
        if (getIntent().hasExtra("routerParam")) {
            String json = getIntent().getStringExtra("routerParam");
            if (!TextUtils.isEmpty(json)) {
                try {
                    JSONObject jsonObject = new JSONObject(json);
                    id = jsonObject.getInt("id");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    protected void initDataAndEvent() {

        fmIdList.clear();

185
        EventBus.getDefault().register(this);
徐健 committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301

        if (null == getIntent()) {
            finish();
            return;
        }
        Bundle bundle = getIntent().getBundleExtra("bundle");
        if (null != bundle) {
            id = bundle.getInt(ID, 0);
            isSplash = bundle.getBoolean("isSplash", false);
        }
        //路由跳转 取值
        getParam();
        tb_title = findViewById(R.id.tb_title);
        iv_play = findViewById(R.id.iv_play);
        tv_fm_title = findViewById(R.id.tv_fm_title);
        tv_anchor = findViewById(R.id.tv_anchor);
        tv_like = findViewById(R.id.tv_like);
        tv_listen = findViewById(R.id.tv_listen);
        iv_love = findViewById(R.id.iv_love);
        iv_next = findViewById(R.id.iv_next);
        iv_last = findViewById(R.id.iv_last);
        iv_share = findViewById(R.id.iv_share);
        ll_bottom = findViewById(R.id.ll_bottom);
        tv_currentTime = findViewById(R.id.tv_currentTime);
        tv_allTime = findViewById(R.id.tv_allTime);
        fm_progress = findViewById(R.id.fm_progress);
        fmSurfaceView = findViewById(R.id.fmSurfaceView);
        ll_last_time = findViewById(R.id.ll_last_time);
        fm_img = findViewById(R.id.fm_img);
        tv_like_icon = findViewById(R.id.tv_like_icon);
        tv_listen_icon = findViewById(R.id.tv_listen_icon);
        refresh_icon = findViewById(R.id.refresh_icon);
        fm_card = findViewById(R.id.fm_card);

        iv_play.setOnClickListener(this);
        iv_love.setOnClickListener(this);
        iv_next.setOnClickListener(this);
        iv_last.setOnClickListener(this);
        iv_share.setOnClickListener(this);
        initRefreshAnimate();
        init();
        initSurfaceView();
        initImg();
    }

    @SuppressLint("WrongConstant")
    private void initRefreshAnimate() {
        anim = ValueAnimator.ofFloat(1f, 1.5f, 1f);
        anim.setDuration(1000);
        anim.setStartDelay(1000);
        anim.setRepeatCount(ValueAnimator.INFINITE);
        anim.setRepeatMode(ValueAnimator.INFINITE);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        int refreshIconWidth = RxImageTool.dp2px(25f);
        anim.addUpdateListener(animation -> {
            refresh_icon.setVisibility(View.VISIBLE);
            float currentValue = (float) animation.getAnimatedValue();
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) (refreshIconWidth * currentValue), (int) (refreshIconWidth * currentValue));
            params.addRule(RelativeLayout.CENTER_IN_PARENT);
            refresh_icon.setLayoutParams(params);
        });
    }

    private void initSurfaceView() {
        int width = RxDeviceTool.getScreenWidth(this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width, width);
        fmSurfaceView.setLayoutParams(params);
    }

    private void initImg() {
        int screenWidth = RxDeviceTool.getScreenWidth(this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(screenWidth, screenWidth);
        ll_last_time.setLayoutParams(params);

        int width = screenWidth * 140 / 375;
        LinearLayout.LayoutParams cardParams = new LinearLayout.LayoutParams(width, width);
        fm_card.setRadius(width / 2);
        fm_card.setLayoutParams(cardParams);
        FrameLayout.LayoutParams imgParams = new FrameLayout.LayoutParams(width, width);
        fm_img.setLayoutParams(imgParams);
    }

    int changeProgress = 0;

    void init() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                window.setStatusBarColor(Color.TRANSPARENT);
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            } else {
                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }
        }
        fm_progress.setMax(max_progress);
        tb_title.setDivideVisible(View.GONE);
        tb_title.setLeftListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Back();
            }
        });
        tb_title.setOnRightTextClick(new TitleBar.OnTitleBarTextClick() {
            @Override
            public void onClick(View view, boolean isActive) {
                startActivity(new Intent(FMDetailActivity.this, FMActivity.class));
            }
        });
        LogUtil.d("id " + id);
        if (PlayerFloatHelper.Companion.getFmId() == id) {
            refresh_icon.setVisibility(View.GONE);
            anim.cancel();
            if (AudioPlayer.Companion.get().isPlaying()) {
302
                iv_play.setImageResource(R.drawable.fm_stop_2);
徐健 committed
303
            } else {
304
                iv_play.setImageResource(R.drawable.fm_play_2);
徐健 committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
            }
            LogUtil.d("id equal " + id);
        }
        getFMDetail(id, true);
        fm_progress.setProgress(0);
        fm_progress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                allTime = Integer.parseInt(String.valueOf(AudioPlayer.Companion.get().getDuration()));
                int current = seekBar.getProgress() * allTime / 1000;
                tv_allTime.setText(formatter.format(allTime));
                tv_currentTime.setText(formatter.format(current));
                changeProgress = progress;
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
323
                iv_play.setImageResource(R.drawable.fm_play_2);
徐健 committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
                AudioPlayer.Companion.get().pausePlayer();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                allTime = Integer.parseInt(String.valueOf(AudioPlayer.Companion.get().getDuration()));
                int current = seekBar.getProgress() * allTime / 1000;
                tv_allTime.setText(formatter.format(allTime));
                tv_currentTime.setText(formatter.format(current));
                AudioPlayer.Companion.get().seekTo(-1, current);
            }
        });
//        player.getMediaPlayer().setOnSeekCompleteListener(mp -> iv_play.setImageResource(R.drawable.fm_stop));

    }

    /**
     * @param id
     * @param type 为true则为下一首,否则为上一首
     */
    private void getFMDetail(int id, boolean type) {
        canNext = false;
        if (PlayerFloatHelper.Companion.getFmId() != id) {
            anim.start();
348
            iv_play.setImageResource(R.drawable.fm_stop_2);
徐健 committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
            fmSurfaceView.stopTimer();
            fm_progress.setEnabled(false);
            if (type) {
                fmIdList.add(id);
            } else {
                fmIdList.remove(fmIdList.size() - 1);
            }
        }
        FmDataManager.INSTANCE.getHttp().fmDetail(new DetailParam(id))
                .compose(RxUtils.resultData())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(fmDetail -> {
                    this.fmDetail = fmDetail;
                    this.id = fmDetail.getId();
                    setData();
                }, new ThrowableConsumer() {
                    @Override
                    public void accept(@NotNull String msg) {
                        ToastHelper.Companion.show(msg);
                    }
                });
    }

    void setData() {
        if (!TextUtils.isEmpty(fmDetail.getImage_url())) {
            GlideApp.with(this)
                    .load(fmDetail.getImage_url())
                    .placeholder(fm_img.getDrawable())
                    .transform(new GlideCircleRingTransform(this))
                    .into(fm_img);
        }
        if (!TextUtils.isEmpty(fmDetail.getAuthor())) {
            tv_anchor.setText("主播:" + fmDetail.getAuthor());
            tv_anchor.setVisibility(View.VISIBLE);
        }
        if (!TextUtils.isEmpty(fmDetail.getTitle())) {
            tv_fm_title.setText(fmDetail.getTitle());
            tv_fm_title.setVisibility(View.VISIBLE);
        }
        if (!TextUtils.isEmpty(fmDetail.getCount_favorite())) {
            tv_like.setText("" + fmDetail.getCount_favorite());
            tv_like_icon.setVisibility(View.VISIBLE);
            tv_like.setVisibility(View.VISIBLE);
        }
        if (!TextUtils.isEmpty(String.valueOf(fmDetail.getHits()))) {
            tv_listen.setText("" + fmDetail.getHits());
            tv_listen_icon.setVisibility(View.VISIBLE);
            tv_listen.setVisibility(View.VISIBLE);
        }
        if (fmDetail.is_favorite() == 1) {//love
399
            iv_love.setImageResource(R.drawable.fm_love_h_2);
徐健 committed
400
        } else {
401
            iv_love.setImageResource(R.drawable.fm_love_n_2);
徐健 committed
402 403 404 405 406 407 408
        }
        canNext = true;
        LogUtil.d("fmDetail.id " + fmDetail.getId());
        if (PlayerFloatHelper.Companion.getFmId() != fmDetail.getId()) {
            if (!TextUtils.isEmpty(fmDetail.getFm_url())) {
                Music music = new Music();
                music.setPath(fmDetail.getFm_url());
409 410 411 412
                music.setAlbum(fmDetail.getImage_url());
                music.setArtist(fmDetail.getAuthor());
                music.setCoverPath(fmDetail.getImage_url());
                music.setTitle(fmDetail.getTitle());
徐健 committed
413 414 415 416 417
                AudioPlayer.Companion.get().prev();
                AudioPlayer.Companion.get().singlePlay(music, false);
            }
            LogUtil.d("fmDetail.id not equal " + fmDetail.getId());
            HashMap<String,String> map = new HashMap();
严久程 committed
418
            PlayerFloatHelper.Companion.getPlayTempData().clear();
徐健 committed
419 420 421 422 423
            map.put("fmId", String.valueOf(fmDetail.getId()));
            map.put("fmTitle", String.valueOf(fmDetail.getTitle()));
            map.put("fmAuthor", String.valueOf(fmDetail.getAuthor()));
            map.put("fmImageUrl", String.valueOf(fmDetail.getImage_url()));
            PlayerFloatHelper.Companion.setPlayTempData(map);
424
            iv_play.setImageResource(R.drawable.fm_stop_2);
徐健 committed
425 426 427 428 429 430 431 432 433 434 435 436
            fm_progress.setProgress(0);
        }else {
            this.time = Integer.parseInt(String.valueOf(AudioPlayer.Companion.get().getAudioPosition()));
                    //PlayProgressUtil.INSTANCE.getProgress(this, fmDetail.getFm_url());
            updateThread();
        }
        AudioPlayer.Companion.get().addOnPlayEventListener(this);
    }

    //todo xujian 通知栏改变状态修改应用内播放状态图标
//    public void onEventMainThread(UpdatePlayStatusEvent status) {
//        if (PlayerFloatHelper.Companion.isFmPlaying()) {
437
//            iv_play.setImageResource(R.drawable.fm_stop_2);
徐健 committed
438
//        } else {
439
//            iv_play.setImageResource(R.drawable.fm_fm_play_2);
徐健 committed
440 441 442
//        }
//    }

443 444 445 446 447 448
    public void onEvent(UserLoginEvent event) {
        if (isToTrend) {
            isToTrend = false;
            toTrend();
        }
    }
徐健 committed
449 450 451 452 453 454 455

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.iv_play) {
            if (AudioPlayer.Companion.get().isPlaying()) {
                AudioPlayer.Companion.get().pausePlayer();
456
                iv_play.setImageResource(R.drawable.fm_play_2);
徐健 committed
457 458 459
                fmSurfaceView.stopTimer();
            } else {
                AudioPlayer.Companion.get().startPlayer();
460
                iv_play.setImageResource(R.drawable.fm_stop_2);
徐健 committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
                fmSurfaceView.playTimer();
            }

        } else if (i == R.id.iv_love) {
            if (!FMIn.INSTANCE.isLogin()) {
                startActivity(FMIn.INSTANCE.loginWayIntent(this));
                return;
            }
            collect();

        } else if (i == R.id.iv_next) {// 锁
            if (canNext)
                getFMDetail(fmDetail.getNext_id(), true);

        } else if (i == R.id.iv_last) {
            //这里调用canNext同样的状态控制,以及判定是否还有上一首,如果id数组大小为1,则当前已经是第一首了
            if (canNext && fmIdList.size() >= 2) {
                getFMDetail(fmIdList.get(fmIdList.size() - 2), false);
            } else if (fmIdList.size() <= 1) {
                ToastHelper.Companion.show("前面没有了哦");
            }
        } else if (i == R.id.iv_share) {
            share();
        }
    }


    private void share() {
        if (fmDetail == null)
            return;
严久程 committed
491
        YDLShareDialog dialog = YDLShareDialog.Companion.style1(this, fmDetail.getTitle(), fmDetail.getShare_url(), "", fmDetail.getImage_url());
徐健 committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
        dialog.setCallBack(type -> {
            if (1 == type) {
                if (!FMIn.INSTANCE.isLogin()) {
                    isToTrend = true;
                    startActivity(FMIn.INSTANCE.loginWayIntent(this));
                } else {
                    //分享到心事动态
                    toTrend();
                }
            }
        });
        dialog.show(getFragmentManager(), "lose");
    }

    private void toTrend() {
        //分享到心事动态
        Intent fmIntent = FMIn.INSTANCE.publisFmToTrend(FMDetailActivity.this, fmDetail.getShare_url(), fmDetail.getImage_url(), fmDetail.getTitle());
        if (null != fmIntent) {
            FMDetailActivity.this.startActivity(fmIntent);
        }
    }

    private void collect() {
        FmDataManager.INSTANCE.getHttp().favFM(new FavParam(id))
                .compose(RxUtils.resultData())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(favFM -> {
                    if (favFM.getStatus() == 1) {
520
                        iv_love.setImageResource(R.drawable.fm_love_h_2);
徐健 committed
521
                    } else {
522
                        iv_love.setImageResource(R.drawable.fm_love_n_2);
徐健 committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
                    }
                }, new ThrowableConsumer() {
                    @Override
                    public void accept(@NotNull String msg) {
                        ToastHelper.Companion.show(msg);
                    }
                });
    }

    private void updateAnimateStatus() {
        //如果FM是在播放状态,那么就进行动画
        if (AudioPlayer.Companion.get().isPlaying()) {
            fmSurfaceView.playTimer();
        } else {
            fmSurfaceView.stopTimer();
        }
    }

    public void updateThread() {
        runOnUiThread(() -> {
            allTime = Integer.parseInt(String.valueOf(AudioPlayer.Companion.get().getDuration()));
            currentTime.setTime(time - 8 * 60 * 60 * 1000);
            int percent = (int) (1000.0 * time / allTime);
            fm_progress.setProgress(percent);
            tv_currentTime.setText(formatter.format(currentTime));
            tv_allTime.setText(formatter.format(allTime));
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
555
        fmSurfaceView.surfaceCreated(null);
徐健 committed
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578

        if (PlayerFloatHelper.Companion.isShow(this)) {
            PlayerFloatHelper.Companion.removeView(this);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Back();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private void Back() {
        if (isSplash) {
//            FMOut.INSTANCE.startMain(this);
konghaorui committed
579
            FMIn.INSTANCE.mainIntent(this);
徐健 committed
580 581 582 583 584 585 586 587 588 589 590
            finish();
        } else {
            finish();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        anim.cancel();

591
        EventBus.getDefault().unregister(this);
徐健 committed
592 593 594 595 596 597 598 599 600 601
        AudioPlayer.Companion.get().removeOnPlayEventListener(this);
    }

    @Override
    public void onChange(@NotNull Music music) {

    }

    @Override
    public void onPlayerStart() {
konghaorui committed
602 603
        iv_play.setImageResource(R.drawable.fm_stop_2);
        fmSurfaceView.playTimer();
徐健 committed
604 605 606 607
    }

    @Override
    public void onPlayerPause() {
konghaorui committed
608 609
        iv_play.setImageResource(R.drawable.fm_play_2);
        fmSurfaceView.stopTimer();
徐健 committed
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
    }

    @Override
    public void onPublish(int percent, long currentPosition) {
        this.time = Integer.parseInt(String.valueOf(currentPosition));
        updateThread();
        updateAnimateStatus();
    }

    @Override
    public void onBufferingUpdate(int percent) {

    }

    @Override
    public void onPrepared(long duration) {
        this.allTime = Integer.parseInt(String.valueOf(duration));

        iv_play.setVisibility(View.VISIBLE);
        refresh_icon.setVisibility(View.GONE);
        anim.cancel();
        fm_progress.setEnabled(true);
632
        iv_play.setImageResource(R.drawable.fm_stop_2);
徐健 committed
633 634 635 636 637 638 639 640 641 642
        fmSurfaceView.playTimer();
    }

    @Override
    public void onComplete() {
        fm_progress.setProgress(max_progress);
        updateAnimateStatus();
        getFMDetail(fmDetail.getNext_id(), true);
    }
}