本文整理匯總了PHP中Stats::get_last_song方法的典型用法代碼示例。如果您正苦於以下問題:PHP Stats::get_last_song方法的具體用法?PHP Stats::get_last_song怎麽用?PHP Stats::get_last_song使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Stats
的用法示例。
在下文中一共展示了Stats::get_last_song方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save_songplay
/**
* save_songplay
* This takes care of queueing and then submitting the tracks.
*/
public function save_songplay($song)
{
// Before we start let's pull the last song submitted by this user
$previous = Stats::get_last_song($this->user_id);
$diff = time() - $previous['date'];
// Make sure it wasn't within the last min
if ($diff < 60) {
debug_event($this->name, 'Last song played within ' . $diff . ' seconds, not recording stats', '3');
return false;
}
if ($song->time < 30) {
debug_event($this->name, 'Song less then 30 seconds not queueing', '3');
return false;
}
// Make sure there's actually a username and password before we keep going
if (!$this->username || !$this->password) {
debug_event($this->name, 'Username or password missing', '3');
return false;
}
// Create our scrobbler with everything this time and then queue it
$scrobbler = new scrobbler($this->username, $this->password, $this->hostname, $this->port, $this->path, $this->challenge, 'turtle.libre.fm');
// Check to see if the scrobbling works
if (!$scrobbler->queue_track($song->f_artist_full, $song->f_album_full, $song->title, time(), $song->time, $song->track)) {
// Depending on the error we might need to do soemthing here
return false;
}
// Go ahead and submit it now
if (!$scrobbler->submit_tracks()) {
debug_event($this->name, 'Error Submit Failed: ' . $scrobbler->error_msg, '3');
if ($scrobbler->reset_handshake) {
debug_event($this->name, 'Re-running Handshake due to error', '1');
$this->set_handshake($this->user_id);
// Try try again
if ($scrobbler->submit_tracks()) {
return true;
}
}
return false;
}
debug_event($this->name, 'Submission Successful', '5');
return true;
}
示例2: save_mediaplay
/**
* save_songplay
* This takes care of queueing and then submitting the tracks.
*/
public function save_mediaplay($song)
{
// Only support songs
if (strtolower(get_class($song)) != 'song') {
return false;
}
// Make sure there's actually a session before we keep going
if (!$this->challenge) {
debug_event($this->name, 'Session key missing', '5');
return false;
}
// Let's pull the last song submitted by this user
$previous = Stats::get_last_song($this->user_id);
$diff = time() - $previous['date'];
// Make sure it wasn't within the last min
if ($diff < 60) {
debug_event($this->name, 'Last song played within ' . $diff . ' seconds, not recording stats', '3');
return false;
}
if ($song->time < 30) {
debug_event($this->name, 'Song less then 30 seconds not queueing', '3');
return false;
}
// Create our scrobbler and then queue it
$scrobbler = new scrobbler($this->api_key, $this->scheme, $this->api_host, $this->challenge, $this->secret);
// Check to see if the scrobbling works by queueing song
if (!$scrobbler->queue_track($song->f_artist_full, $song->f_album_full, $song->title, time(), $song->time, $song->track)) {
return false;
}
// Go ahead and submit it now
if (!$scrobbler->submit_tracks()) {
debug_event($this->name, 'Error Submit Failed: ' . $scrobbler->error_msg, '3');
return false;
}
debug_event($this->name, 'Submission Successful', '5');
return true;
}
示例3: save_mediaplay
/**
* save_songplay
* This takes care of queueing and then submitting the tracks.
*/
public function save_mediaplay($song)
{
// Only support songs
if (strtolower(get_class($song)) != 'song') {
return false;
}
// Before we start let's pull the last song submitted by this user
$previous = Stats::get_last_song($this->user_id);
$user = new User($this->user_id);
$diff = time() - $previous['date'];
// Make sure it wasn't within the last 10sec
if ($diff < 10) {
debug_event($this->name, 'Last song played within ' . $diff . ' seconds, not recording stats', '3');
return false;
}
// Make sure there's actually a server address before we keep going
if (!$this->address) {
debug_event($this->name, 'Server address missing', '3');
return false;
}
$message = str_replace("%user", $user->fullname, $this->message);
$message = str_replace("%artist", $song->f_artist_full, $message);
$message = str_replace("%album", $song->f_album_full, $message);
$message = str_replace("%title", $song->title, $message);
$growl = $this->get_growl();
$growl->notify('Now Playing', $message);
debug_event($this->name, 'Submission Successful', '5');
return true;
}