Esempio n. 1
0
/*
** Handles the SetRating bang.
**
*/
void PlayerITunes::SetRating(int rating)
{
	IITTrack* track;
	HRESULT hr = m_iTunes->get_CurrentTrack(&track);
	if (SUCCEEDED(hr) && track)
	{
		rating *= 20;
		track->put_Rating((long)rating);
		track->Release();
	}
}
Esempio n. 2
0
/*
** Handles the SetRepeat bang.
**
*/
void PlayerITunes::SetRepeat(bool state)
{
	IITTrack* track;
	HRESULT hr = m_iTunes->get_CurrentTrack(&track);
	if (SUCCEEDED(hr) && track)
	{
		IITPlaylist* playlist;
		hr = track->get_Playlist(&playlist);
		if (SUCCEEDED(hr))
		{
			m_Repeat = state;
			playlist->put_SongRepeat((ITPlaylistRepeatMode)m_Repeat);

			playlist->Release();
		}

		track->Release();
	}
}
Esempio n. 3
0
/*
** Handles the SetShuffle bang.
**
*/
void PlayerITunes::SetShuffle(bool state)
{
	IITTrack* track;
	HRESULT hr = m_iTunes->get_CurrentTrack(&track);
	if (SUCCEEDED(hr) && track)
	{
		IITPlaylist* playlist;
		hr = track->get_Playlist(&playlist);
		if (SUCCEEDED(hr))
		{
			m_Shuffle = state;
			VARIANT_BOOL shuffle = m_Shuffle ? VARIANT_TRUE : VARIANT_FALSE;
			playlist->put_Shuffle(shuffle);

			playlist->Release();
		}

		track->Release();
	}
}
Esempio n. 4
0
/*
** Called by iTunes event handler on track change.
**
*/
void PlayerITunes::OnTrackChange()
{
	IITTrack* track;
	HRESULT hr = m_iTunes->get_CurrentTrack(&track);
	if (SUCCEEDED(hr) && track)
	{
		BSTR tmpStr;
		long tmpVal;

		// Get metadata
		track->get_Artist(&tmpStr);
		tmpStr ? (m_Artist = tmpStr) : m_Artist.clear();

		track->get_Name(&tmpStr);
		tmpStr ? (m_Title = tmpStr) : m_Title.clear();

		track->get_Album(&tmpStr);
		tmpStr ? (m_Album = tmpStr) : m_Album.clear();

		track->get_Genre(&tmpStr);;
		tmpStr ? (m_Genre = tmpStr) : m_Genre.clear();

		track->get_Duration(&tmpVal);
		m_Duration = (UINT)tmpVal;

		// Rating is 0 - 100, divide to 0 - 5
		track->get_Rating(&tmpVal);
		tmpVal /= 20L;
		m_Rating = (UINT)tmpVal;

		track->get_TrackNumber(&tmpVal);
		m_Number = (UINT)tmpVal;

		track->get_Year(&tmpVal);
		m_Year = (UINT)tmpVal;

		IITPlaylist* playlist;
		hr = track->get_Playlist(&playlist);
		if (SUCCEEDED(hr))
		{
			ITPlaylistRepeatMode repeat;
			hr = playlist->get_SongRepeat(&repeat);
			if (SUCCEEDED(hr))
			{
				m_Repeat = repeat != ITPlaylistRepeatModeOff;
			}

			playlist->Release();
		}

		IITFileOrCDTrack* file;
		hr = track->QueryInterface(&file);
		if (SUCCEEDED(hr))
		{
			file->get_Location(&tmpStr);
			file->Release();
			if (tmpStr && wcscmp(tmpStr, m_FilePath.c_str()) != 0)
			{
				++m_TrackCount;
				m_FilePath = tmpStr;

				if (m_Measures & MEASURE_COVER)
				{
					m_CoverPath.clear();

					// Check for embedded art through iTunes interface
					IITArtworkCollection* artworkCollection;
					hr = track->get_Artwork(&artworkCollection);

					if (SUCCEEDED(hr))
					{
						long count;
						artworkCollection->get_Count(&count);

						if (count > 0)
						{
							IITArtwork* artwork;
							hr = artworkCollection->get_Item(1, &artwork);

							if (SUCCEEDED(hr))
							{
								_bstr_t coverPath = m_TempCoverPath.c_str();
								hr = artwork->SaveArtworkToFile(coverPath);
								if (SUCCEEDED(hr))
								{
									m_CoverPath = m_TempCoverPath;
								}

								artwork->Release();
							}
						}

						artworkCollection->Release();
					}
				}

				if (m_Measures & MEASURE_LYRICS)
				{
					FindLyrics();
				}
			}
		}

		track->Release();
	}
	else
	{
		ClearData(false);
	}
}
std::string CiTunes::GetCurrentSongTitle_iTunes()
{
	Init();

	using std::string;
	using std::wstring;
 
	IITTrack *iITrack = 0;

	// String operations done in a wstring, then converted for return
	wstring wstrRet;
	string strRet;
 
	try
	{
 		BSTR bstrURL = 0;
 
		if(m_iITunes)
		{
			ITPlayerState iIPlayerState;

			m_iITunes->get_CurrentTrack(&iITrack);
			m_iITunes->get_CurrentStreamURL((BSTR *)&bstrURL);	

			if(iITrack)
			{
				BSTR bstrTrack = 0;

				iITrack->get_Name((BSTR *)&bstrTrack);
				
				// Add song title
				if(bstrTrack)
					wstrRet += bstrTrack;

				iITrack->Release();
			}
			else
			{
				// Couldn't get track name
			}

			// Add url, if present
			if(bstrURL)
			{
				wstrRet += L" ";
				wstrRet += bstrURL;
			}

			m_iITunes->get_PlayerState(&iIPlayerState);

			// Add player state, if special
			switch(iIPlayerState)
			{
			case ITPlayerStatePlaying:
			default:
				break;
			case ITPlayerStateStopped:
				wstrRet += L" [stopped]";
				break;
			case ITPlayerStateFastForward:
				wstrRet += L" [fast]";
				break;
			case ITPlayerStateRewind:
				wstrRet += L" [rewind]";
				break;
			}

			/*m_iITunes->Release();*/			
		}
		else
		{
			// iTunes interface not found/failed
			wstrRet = L"";
		}

	}
	catch(...)
	{
 
			SAFE_RELEASE(iITrack);
			ReleaseiTunes();
	}
 

	// Convert the result from wstring to string
	size_t len = wstrRet.size();
	strRet.resize(len);
	for(size_t i = 0; i < len; i++)
		strRet[i] = static_cast<char>(wstrRet[i]);

	return strRet;
}
void CiTunes::GetPlaylist()
{
	Init();
	long lSourceID;
    long lPlaylistID;
    long lTrackId;
    long countSource;
 
    
    IITObject * pObject;
//    IITUserPlaylist * pUserPlaylist;
    IITSourceCollection * pCollection;      
       
    USES_CONVERSION;       

    short bIsSmart=0;

    HRESULT hr=m_iITunes->get_Sources(&pCollection); 
    hr=pCollection->get_Count (&countSource);

    IITSource * pSource = NULL;
    IITPlaylistCollection * pPlaylistCollection = NULL;
    IITPlaylist * pPlaylist = NULL;
    IITTrackCollection * pTrackCollection = NULL;
    IITTrack * pTrack = NULL;

    CComPtr<IITFileOrCDTrack> fileTrack;

    long countPlaylist;
    long countTracklist;
    CComBSTR bstrName;

    for(long i=1;i<=countSource;i++)
    {
        hr=pCollection->get_Item (i,&pSource);
        //
        pSource->get_SourceID (&lSourceID);
        pSource->get_Playlists (&pPlaylistCollection);
        pPlaylistCollection->get_Count (&countPlaylist);

        for(long j=7;j<=countPlaylist;j++)//get playlists
        {
            hr=pPlaylistCollection->get_Item (j,&pPlaylist);

            pPlaylist->get_PlaylistID (&lPlaylistID);          
		    CLOUD_MEIDA_METADATA_STRUCT* cmd = new CLOUD_MEIDA_METADATA_STRUCT();
			InitMetadataStruct(cmd);
			              
            hr=m_iITunes->GetITObjectByID (lSourceID,lPlaylistID,0,0,&pObject);
            pObject->get_Name (&bstrName);

            CComPtr<IITUserPlaylist> spUserPlaylist; 
            hr=pPlaylist->QueryInterface(&spUserPlaylist);

            if(SUCCEEDED(hr))
            {
			/*	spUserPlaylist->get_Smart(&bIsSmart);
                if(bIsSmart==0)*/
                //{
            /*        ITUserPlaylistSpecialKind  plKind;
                    spUserPlaylist->get_SpecialKind (&plKind);*/
                    //if(plKind==ITUserPlaylistSpecialKindPodcasts)
                    //{
                        //AfxMessageBox(OLE2T(bstrName));

                        spUserPlaylist->get_Tracks (&pTrackCollection);
                        pTrackCollection->get_Count (&countTracklist);

 						long _lSourceID,_lPlaylistID,_lTrackId, _lDatabaseID;

						pPlaylist->get_SourceID (&_lSourceID);
						pPlaylist->get_PlaylistID(&_lPlaylistID);
						pPlaylist->get_TrackID(&_lTrackId);
						pPlaylist->get_TrackDatabaseID(&_lDatabaseID);

						cmd->UID = cmd->PlaylistID = GetGUID(_lSourceID,_lPlaylistID,_lTrackId,_lDatabaseID);	
						cmd->PlaylistName = OLE2T(bstrName);
						cmd->Count = (int)countTracklist;
						cmd->Source = PLAYER_TYPE_iTunes;
						cmd->MediaType = MEDIA_TYPE_audio;
						cmd->MetadataType = _Metadata_Playlist;

                        for(long k=1;k<=countTracklist;k++)//get tracks form playlist
                        {

								hr=pTrackCollection->get_Item (k,&pTrack);

								CComPtr<IITFileOrCDTrack> spFileTrack;

								 hr=pTrack->QueryInterface (__uuidof(spFileTrack),(void **)&spFileTrack);

								 if(SUCCEEDED(hr))
								 {					
								 		spFileTrack->get_SourceID (&_lSourceID);
										spFileTrack->get_PlaylistID(&_lPlaylistID);
										spFileTrack->get_TrackID(&_lTrackId);
										spFileTrack->get_TrackDatabaseID(&_lDatabaseID);
										cmd->ContentIDs.AddTail(GetGUID(_lSourceID,_lPlaylistID,_lTrackId,_lDatabaseID));	
						/*			 GetTrackInfo(spFileTrack );*/
								 }

							 spFileTrack.Release();

							 pTrack->Release();
                            //pTrack->get_TrackID(&lTrackId);
                            //pTrack->get_Name (&bstrName);
                            //AfxMessageBox(OLE2T(bstrName));
                        //}
                    //}
						 }   
						if(countTracklist >0)
							m_litem->insert(std::make_pair(cmd->UID,cmd));

            }
			spUserPlaylist.Release();
        }
		if(pSource!= NULL)
			SAFE_RELEASE(pSource);
		if(pPlaylistCollection!= NULL)
			SAFE_RELEASE(pPlaylistCollection);
		if(pPlaylist!= NULL)
			SAFE_RELEASE(pPlaylist);
		if(pTrackCollection!= NULL)
			SAFE_RELEASE(pTrackCollection);
     }
		ReleaseiTunes();
}