Example #1
0
void
ScrobSocket::start( const Track& t )
{
    m_track = t;
    transmit( "START c=bof" "&"
                    "a=" + encodeAmp( t.artist() ) + "&"
                    "t=" + encodeAmp( t.title() ) + "&"
                    "b=" + encodeAmp( t.album() ) + "&"
                    "l=" + QString::number( t.duration() ) + "&"
                    "p=" + encodeAmp( t.url().path() ) + '\n' );
}
Example #2
0
void
ITunesScript::callback( CFDictionaryRef info )
{
    ITunesDictionaryHelper dict( info );
    State const previousState = m_state;
    m_state = dict.state;
    
    switch (m_state)
    {
        case Paused:
            transmit( "PAUSE c=osx\n" );
            break;

        case Stopped:
            transmit( "STOP c=osx\n" );
            break;
            
        case Playing:
            if (!isMusic())
            {
                qDebug() << "Ignoring current track because it isn't music.";
                break;
            }

            dict.determineTrackInformation();

            // if the track is restarted it has the same pid and a position of 0
            if (m_previousPid == dict.pid && dict.position != 0)
            {
                if (previousState == Paused)
                    transmit( "RESUME c=osx\n" );
                //else the user changed some metadata or the track's rating etc.
            }
            else
            {
                transmit( "START c=osx"
                               "&a=" + encodeAmp( dict.artist ) +
                               "&t=" + encodeAmp( dict.name ) +
                               "&b=" + encodeAmp( dict.album ) +
                               "&l=" + QString::number( dict.duration ) +
                               "&p=" + encodeAmp( dict.path ) + '\n' );

                m_previousPid = dict.pid;
            }
            break;

        default:
          qWarning() << "Unknown state.";
          break;
    }
}