Search in sources :

Example 1 with SongListAdapter

use of com.tencent.iot.explorer.device.tme.adapter.SongListAdapter in project iot-device-java by tencentyun.

the class TmeMainActivity method initView.

private void initView() {
    mGetSongBtn = findViewById(R.id.request_song);
    mSearchIv = findViewById(R.id.search);
    mPreIv = findViewById(R.id.iv_pre);
    mNextIv = findViewById(R.id.iv_next);
    mPlayIv = findViewById(R.id.iv_play);
    mPlayModeIv = findViewById(R.id.iv_play_mode);
    mInputEt = findViewById(R.id.input);
    mCurrentSongTv = findViewById(R.id.tv_current_song);
    mPlayList = findViewById(R.id.play_list);
    mSmartRefreshLayout = findViewById(R.id.smart_refreshLayout);
    mTimeTv = findViewById(R.id.tv_time);
    mSeekBar = findViewById(R.id.sb_seek_bar);
    mVolumeSeekBar = findViewById(R.id.sb_volume);
    mSwitch = findViewById(R.id.tb_switch);
    mSpinner = findViewById(R.id.sp_quality);
    mSmartRefreshLayout.setEnableLoadMore(true);
    mSmartRefreshLayout.setRefreshFooter(new ClassicsFooter(this));
    mGetSongBtn.setOnClickListener(this);
    mSearchIv.setOnClickListener(this);
    mPreIv.setOnClickListener(this);
    mNextIv.setOnClickListener(this);
    mPlayIv.setOnClickListener(this);
    mPlayModeIv.setOnClickListener(this);
    mPlayList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mPlayList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    mAdapter = new SongListAdapter(this, mSongList);
    mAdapter.setOnItemClickListener(new SongListAdapter.ItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Song song = mSongList.get(position);
            mCurrentSongTv.setText(song.songName + "-" + song.singerName);
            playSong(position);
        }
    });
    mPlayList.setAdapter(mAdapter);
    mSmartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore(RefreshLayout refreshLayout) {
            refreshLayout.finishLoadMore();
            page++;
            if (operationType == TYPE_SEARCH) {
                doSearch(keyword);
            } else if (operationType == TYPE_SONG_LIST) {
                getSongListById(songListId, songListType);
            }
        }
    });
    mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                TXLog.d(TAG, "seek =" + seekValue);
                seekValue = progress;
                UltimateSongPlayer.getInstance().seekTo(seekValue * 1000);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            mIsSeekBarTouching = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (seekValue >= 60) {
                SongInfo songInfo = UltimateSongPlayer.getInstance().getSongInfo();
                if (songInfo != null && songInfo.isTryListen()) {
                    TmeMainActivity.this.runOnUiThread(() -> ToastUtil.showS("当前歌曲只支持试听60秒~"));
                }
            }
            UltimateSongPlayer.getInstance().seekTo(seekValue * 1000);
            mIsSeekBarTouching = false;
            reportProperty(Common.PROPERTY_PLAY_POSITION, seekValue);
        }
    });
    mVolumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                TXLog.d(TAG, "seek =" + volumeSeekValue);
                volumeSeekValue = progress;
                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, AudioManager.FLAG_PLAY_SOUND);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            int volume = (int) ((volumeSeekValue / (maxVolume * 1.00)) * Common.TOTOAL_VOLUME_DURATION);
            reportProperty(Common.PROPERTY_VOLUME, volume);
        }
    });
    mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                if (mDataTemplateSample != null)
                    return;
                mDataTemplateSample = new TmeDataTemplateSample(TmeMainActivity.this, mBrokerURL, mProductID, mDevName, mDevPSK, new SelfMqttActionCallBack(mProductID, mDevName), JSON_FILE_NAME, new SelfDownStreamCallBack(), mAuthCallback);
                mDataTemplateSample.connect();
            } else {
                if (mDataTemplateSample == null)
                    return;
                mDataTemplateSample.disconnect();
                mDataTemplateSample = null;
            }
        }
    });
    mSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, qualityStrArray));
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (isGetStatusReply) {
                UltimateSongPlayer.getInstance().changeQuality(qualities[position]);
                isGetStatusReply = false;
            } else {
                if (UltimateSongPlayer.getInstance().getCurrentPlayQuality() == qualities[position]) {
                    return;
                }
                // 当前歌曲详情
                SongInfo songInfo = UltimateSongPlayer.getInstance().getSongInfo();
                if (songInfo == null) {
                    ToastUtil.showS("无法切换音质");
                    parent.setSelection(0);
                    return;
                }
                if (songInfo.isTryListen()) {
                    ToastUtil.showS("试听中,无法切换音质");
                    parent.setSelection(0);
                    return;
                }
                if (songInfo.getSupportQualities().contains(qualities[position])) {
                    UltimateSongPlayer.getInstance().changeQuality(qualities[position]);
                    reportProperty(Common.PROPERTY_RECOMMEND_QUALITY, position);
                } else {
                    parent.setSelection(0);
                    ToastUtil.showS(String.format("当前歌曲不支持%s音质", qualityStrArray[position]));
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
Also used : OnLoadMoreListener(com.scwang.smart.refresh.layout.listener.OnLoadMoreListener) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ClassicsFooter(com.scwang.smart.refresh.footer.ClassicsFooter) Song(com.kugou.ultimatetv.entity.Song) RefreshLayout(com.scwang.smart.refresh.layout.api.RefreshLayout) SmartRefreshLayout(com.scwang.smart.refresh.layout.SmartRefreshLayout) SongListAdapter(com.tencent.iot.explorer.device.tme.adapter.SongListAdapter) SongInfo(com.kugou.ultimatetv.entity.SongInfo) TmeDataTemplateSample(com.tencent.iot.explorer.device.tme.data_template.TmeDataTemplateSample) SeekBar(android.widget.SeekBar) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton)

Aggregations

View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Song (com.kugou.ultimatetv.entity.Song)1 SongInfo (com.kugou.ultimatetv.entity.SongInfo)1 ClassicsFooter (com.scwang.smart.refresh.footer.ClassicsFooter)1 SmartRefreshLayout (com.scwang.smart.refresh.layout.SmartRefreshLayout)1 RefreshLayout (com.scwang.smart.refresh.layout.api.RefreshLayout)1 OnLoadMoreListener (com.scwang.smart.refresh.layout.listener.OnLoadMoreListener)1 SongListAdapter (com.tencent.iot.explorer.device.tme.adapter.SongListAdapter)1 TmeDataTemplateSample (com.tencent.iot.explorer.device.tme.data_template.TmeDataTemplateSample)1