gpt4 book ai didi

android - 如何在android中找到音乐应用程序的开始时间和结束时间?

转载 作者:行者123 更新时间:2023-12-02 23:58:26 29 4
gpt4 key购买 nike

我正在开发应捕获音频(FM /音乐)的开始和结束时间的应用程序。我冲浪了很多次,并且知道可以通过audioFocusListener来实现。我已经实现了侦听器,但是无法正确获取值。即,当音频获得焦点而失去焦点时,这没有给出适当的值。
OnAudioFocusChangeListener is not executed when the audio is played and paused?
是否有其他方法可以实现相同目的?

public class AudioManagerExample extends Activity implements OnAudioFocusChangeListener{
AudioReceiver adreceiver;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
am.requestAudioFocus(this,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN)
}

@Override
public void onAudioFocusChange(int focusChange) {
Log.d("AudioManager", "Inside on audio focus change");
if(focusChange == AudioManager.AUDIOFOCUS_GAIN)
Log.d("AudioManager", "audio focus gained");
if(focusChange == AudioManager.AUDIOFOCUS_LOSS)
Log.d("AudioManager", "audio focus lossed");
/* Here i am always getting value -1 */

}
}

提前致谢

最佳答案

我在这里粘贴一些代码,以便您可以根据自己的要求做主意。
希望这能够帮到你,

public void updateProgressBar() 
{
mHandler.postDelayed(mUpdateTimeTask, 100);
}

/**
* Background Runnable thread
* */
private Runnable mUpdateTimeTask = new Runnable()
{
public void run()
{
long totalDuration = mp.getDuration();
long currentDuration = mp.getCurrentPosition();

// Displaying Total Duration time
songTotalDurationLabel.setText(""+utils.milliSecondsToTimer(totalDuration));
// Displaying time completed playing
songCurrentDurationLabel.setText(""+utils.milliSecondsToTimer(currentDuration));

// Updating progress bar
int progress = (int)(utils.getProgressPercentage(currentDuration, totalDuration));
//Log.d("Progress", ""+progress);
songProgressBar.setProgress(progress);

// Running this thread after 100 milliseconds
mHandler.postDelayed(this, 100);
}
};

关于android - 如何在android中找到音乐应用程序的开始时间和结束时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11393563/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com