Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using Gallery interfaces

This section includes sample code for the following scenarios:

  • Gallery synchronization
  • Gallery query

Gallery synchronization

This example shows gallery syncing fs:/shared. When the synchronization is complete, all files in fs:/shared/... are present in the Gallery.

// Function called when Gallery sync is finished
void GalleryExample_SyncCB(void *pUser, AEEGallerySyncStatus *pStatus)
{
   GalleryExample *pMe = (GalleryExample *) pUser;
   
  const char *pMsg = pStatus->cpszSyncInfo?pStatus->cpszSyncInfo:"";
 
  switch (pStatus->nSyncState) {
      case AEEGALLERY_SYNC_STATE_COMPLETE:
         DBGPRINTF("Sync complete, result: %d", pStatus->nSyncErr);
         GalleryExample_SyncDone(pMe, pStatus->nSyncErr);
         break;
      case AEEGALLERY_SYNC_STATE_ADDING:
         DBGPRINTF("Gallery added file: %s", pMsg);
         break;
      case AEEGALLERY_SYNC_STATE_UPDATING:
         DBGPRINTF("Gallery udpated file: %s", pMsg);
         break; 
      default:
         break;
   }
}

// Function that initiates Gallery sync
int GalleryExample_Sync( GalleryExample *pMe )
{
   int nErr = SUCCESS;
   do {
      nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_Gallery, (void **) &pMe->piGallery);
      if (SUCCESS != nErr) {
         DBGPRINTF("Create Gallery failed: %d", nErr);
         break;
      }
      
      nErr = IGallery_MountDirs(pMe->piGallery, "fs:/shared");
      if (SUCCESS != nErr) {
         DBGPRINTF("Gallery mount failed: %d", nErr);
         break;
      }
      
      nErr = IGallery_Sync(pMe->piGallery, "fs:/shared", GalleryExample_SyncCB, pMe);
      if (SUCCESS != nErr) {
         DBGPRINTF("Gallery sync failed: %d", nErr);
         break;
      }
   }
   while (0);

   return nErr;
}

Gallery query

This example shows a Gallery query for all music files in fs:/shared/...

int GalleryExample_Query( GalleryExample *pMe )
{
   int nErr = SUCCESS;
   ISQLStmt *piStmt = NULL;
   AECHAR *pwszFileName = NULL, *pwszTitle = NULL;
   do {
      nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_Gallery,
                  (void **) &pMe->piGallery);
      if (SUCCESS != nErr) {
         DBGPRINTF("Create Gallery failed: %d", nErr);
         break;
      }
      nErr = IGallery_MountDirs(pMe->piGallery, "fs:/shared");
      if (SUCCESS != nErr) {
         DBGPRINTF("Gallery mount failed: %d", nErr);
         break;
      }

      // Gallery query: "SELECT FullPath,Title WHERE MediaType=2"
      #define QUERY_RESULT_COLS L"FullPath,Title"
      #define QUERY_WHERE L"MediaType=2"
      nErr = IGallery_Query(pMe->piGallery, QUERY_RESULT_COLS,
                  QUERY_WHERE, L"", L"", L"", L"", L"", &piStmt);
      if (SUCCESS != nErr) {
         DBGPRINTF("Gallery query prepare failed: %d", nErr);
         break;
      }
      DBGPRINTF("Gallery query results:");
      // Step thru Gallery query results
      while ((nErr = ISQLSTMT_Step(piStmt)) == SQL_ROW) {
         // result column 0 is FullPath
         nErr = ISQLSTMT_GetColumnWText(piStmt, 0, &pwszFileName);
         if (SUCCESS != nErr) {
            break;
         }
         // result column 1 is Title
         nErr = ISQLSTMT_GetColumnWText(piStmt, 1, &pwszTitle);
         if (SUCCESS != nErr) {
            break;
         }
         DBGPRINTF("--Row: %S, Title: \"%S\"", pwszFileName, pwszTitle);
      }
      if (SQL_DONE == nErr) {
         nErr = SUCCESS;
      }
   }
   while (0);
   RELEASEIF(piStmt);
   return nErr;
}
int GalleryExample_Query( GalleryExample *pMe )
{
   int nErr = SUCCESS;
   ISQLStmt *piStmt = NULL;
   AECHAR *pwszFileName = NULL, *pwszTitle = NULL;
   do {
      nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_Gallery,
                  (void **) &pMe->piGallery);
      if (SUCCESS != nErr) {
         DBGPRINTF("Create Gallery failed: %d", nErr);
         break;
      }
      nErr = IGallery_MountDirs(pMe->piGallery, "fs:/shared");
      if (SUCCESS != nErr) {
         DBGPRINTF("Gallery mount failed: %d", nErr);
         break;
      }

      // Gallery query: "SELECT FullPath,Title WHERE MediaType=2"
      #define QUERY_RESULT_COLS L"FullPath,Title"
      #define QUERY_WHERE L"MediaType=2"
      nErr = IGallery_Query(pMe->piGallery, QUERY_RESULT_COLS,
                  QUERY_WHERE, L"", L"", L"", L"", L"", &piStmt);
      if (SUCCESS != nErr) {
         DBGPRINTF("Gallery query prepare failed: %d", nErr);
         break;
      }
      DBGPRINTF("Gallery query results:");
      // Step thru Gallery query results
      while ((nErr = ISQLSTMT_Step(piStmt)) == SQL_ROW) {
         // result column 0 is FullPath
         nErr = ISQLSTMT_GetColumnWText(piStmt, 0, &pwszFileName);
         if (SUCCESS != nErr) {
            break;
         }
         // result column 1 is Title
         nErr = ISQLSTMT_GetColumnWText(piStmt, 1, &pwszTitle);
         if (SUCCESS != nErr) {
            break;
         }
         DBGPRINTF("--Row: %S, Title: \"%S\"", pwszFileName, pwszTitle);
      }
      if (SQL_DONE == nErr) {
         nErr = SUCCESS;
      }
   }
   while (0);
   RELEASEIF(piStmt);
   return nErr;
}