Esempio n. 1
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);
	}
}
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();
}