use of com.kugou.ultimatetv.entity.SongInfo in project iot-device-java by tencentyun.
the class TmeMainActivity method updateQuality.
private boolean updateQuality(int quality) {
// 当前歌曲详情
SongInfo songInfo = UltimateSongPlayer.getInstance().getSongInfo();
if (songInfo == null) {
ToastUtil.showS("无法切换音质");
return false;
}
if (songInfo.isTryListen()) {
ToastUtil.showS("试听中,无法切换音质");
return false;
}
if (songInfo.getSupportQualities().contains(qualities[quality])) {
UltimateSongPlayer.getInstance().changeQuality(qualities[quality]);
mSpinner.setSelection(quality, true);
ToastUtil.showS(qualityStrArray[quality]);
return true;
} else {
ToastUtil.showS(String.format("当前歌曲不支持%s音质", qualityStrArray[quality]));
return false;
}
}
use of com.kugou.ultimatetv.entity.SongInfo 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) {
}
});
}
Aggregations