⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oggplayappview.cpp

📁 OggPlay for Symbian 是symbian上的一个媒体播放程序的源码。它支持ogg,wav等等多媒体格式。
💻 CPP
📖 第 1 页 / 共 5 页
字号:

			  TInt64 nbEntries64 = GetTextArray()->Count()-1;
			  TInt64 picked64 = (rnd64 * nbEntries64) / maxInt64;

#if defined(SERIES60V3)
			  TInt picked = I64LOW(picked64) + 1;
#else
			  TInt picked = picked64.Low() + 1;
#endif

              SelectItem(picked);
          }
      } else
      {
          SelectItem(1);
      }
  }
}

void
COggPlayAppView::Update()
{
  UpdateAnalyzer();
  UpdateListbox();
  UpdateControls();
  UpdateSongPosition();
  UpdateClock(ETrue);
  UpdateVolume();
  UpdatePlaying();
}

void
COggPlayAppView::UpdateAnalyzer()
{
  if (iAnalyzer[iMode]) {
    iAnalyzer[iMode]->Clear();
    iAnalyzer[iMode]->SetStyle(iApp->iAnalyzerState);
  }
}

void
COggPlayAppView::UpdateListbox()
{
  if (iApp->iViewBy!=COggPlayAppUi::ETitle && 
      iApp->iViewBy!=COggPlayAppUi::EFileName) {
    if (iListBox[iMode]) iListBox[iMode]->Redraw();
    return;
  }

  CDesCArray* txt= GetTextArray();
  // BERT: Add a check if there is a song currently playing...
  TBool paused = iApp->iOggPlayback->State()==CAbsPlayback::EPaused;
  const TOggFile* currSong = iApp->iSongList->GetPlayingFile();

  for (TInt i=0; i<txt->Count(); i++) {
    TPtrC sel;
    sel.Set((*txt)[i]);
    TBuf<512> buf(sel);

	COggListBox::TItemTypes type = GetItemType(i);
	if (type!=COggListBox::EBack) {
		TBuf<1> playState;
		if ((type == COggListBox::ETitle) || (type == COggListBox::EFileName) || (type == COggListBox::EPlayList))
		{
			if ( GetFile(i) == currSong ) {
				// Mark as paused or playing
				if (paused)
					playState.Num((TUint) COggListBox::EPaused);
				else
					playState.Num((TUint) COggListBox::EPlaying);
			}
			else
				playState.Num(0);

			buf.Replace(buf.Length()-1, 1, playState);
		}
    }

    txt->Delete(i);
    txt->InsertL(i,buf);
  }
  if (iListBox[iMode]) iListBox[iMode]->Redraw();
}

TBool
COggPlayAppView::CanPlay()
{
  CAbsPlayback::TState playState = iApp->iOggPlayback->State();
  return (playState >= CAbsPlayback::EStreamOpen) && (playState != CAbsPlayback::EPlaying);
}

TBool
COggPlayAppView::CanPause()
{
  return iApp->iOggPlayback->State() == CAbsPlayback::EPlaying;
}

TBool
COggPlayAppView::CanStop()
{
  return iApp->iOggPlayback->State() >= CAbsPlayback::EPaused;
}

TBool
COggPlayAppView::PlayDimmed()
{
  return 
	  (GetSelectedIndex()<0 || GetItemType(GetSelectedIndex())==COggListBox::EBack || 
     iApp->iViewBy==COggPlayAppUi::EArtist || iApp->iViewBy==COggPlayAppUi::EAlbum || 
     iApp->iViewBy==COggPlayAppUi::EGenre || iApp->iViewBy==COggPlayAppUi::ESubFolder ||
     iApp->iViewBy==COggPlayAppUi::ETop) 
    && !(iApp->iOggPlayback->State()==CAbsPlayback::EPaused);
}

void 
COggPlayAppView::UpdateControls()
{
  if (iPlayButton[iMode] && CanPlay()) 
    iPlayButton[iMode]->SetDimmed(PlayDimmed());

  if (iPlayButton2[iMode])
    iPlayButton2[iMode]->SetDimmed(!CanPlay() || PlayDimmed());
  if (iPauseButton2[iMode])
    iPauseButton2[iMode]->SetDimmed(!CanPause());

  if (iPlayButton[iMode]) iPlayButton[iMode]->MakeVisible(CanPlay());
  if (iPauseButton[iMode]) iPauseButton[iMode]->MakeVisible(!CanPlay());
    
  if (iStopButton[iMode]) iStopButton[iMode]->SetDimmed( !CanStop() );

  if (iPosition[iMode]) iPosition[iMode]->SetDimmed( !CanStop() );
 
  if (iRepeatButton[iMode]) iRepeatButton[iMode]->SetState(iApp->iSettings.iRepeat);
  if (iRandomButton[iMode]) iRandomButton[iMode]->SetState(iApp->iSettings.iRandom);
  if (iRepeatIcon[iMode]) iRepeatIcon[iMode]->MakeVisible(iApp->iSettings.iRepeat);
  if (iRandomIcon[iMode]) iRandomIcon[iMode]->MakeVisible(iApp->iSettings.iRandom);
}

void
COggPlayAppView::UpdateSongPosition()
{
#if defined(SERIES60) || defined(SERIES80)
  // Only show "Played" time component when not stopped, i.e. only show 
  // when artist, title etc is displayed.
  if (iPlayed[iMode])
    {
    TBool playedControlIsVisible = (iApp->iOggPlayback->State() > CAbsPlayback::EStopped);
    iPlayed[iMode]->MakeVisible( playedControlIsVisible );
    if( !playedControlIsVisible )
      return;
    }
#endif


  // Update the song position displayed in the menubar (flip open) 
  // or in the TOggCanvas (flip closed):
  //------------------------------------
  TBuf<64> mbuf;
#if defined(SERIES60V3)
  TInt sec= iApp->iOggPlayback->Position()/1000;
#else
  TInt sec= iApp->iOggPlayback->Position().GetTInt()/1000;
#endif

  TInt min= sec/60;
  sec-= min*60;
#if defined(SERIES60V3)
  TInt sectot= iApp->iOggPlayback->Time()/1000;
#else
  TInt sectot= iApp->iOggPlayback->Time().GetTInt()/1000;
#endif

  TInt mintot= sectot/60;
  sectot-= mintot*60;
  mbuf.Format(_L("%02d:%02d / %02d:%02d"), min, sec, mintot, sectot);

#if defined(UIQ)
  if (IsFlipOpen())
  {
    CEikMenuBar* mb = iEikonEnv->AppUiFactory()->MenuBar();
    if (!mb) return;

	// As we cannot officially get the TitleArray, we have to steal it (hack)
    CEikMenuBar::CTitleArray *ta;
    ta = *(CEikMenuBar::CTitleArray**)((char*)mb + sizeof(*mb) - 4*sizeof(void*));
    ta->At(1)->iData.iText.Copy(mbuf);
    mb->SetSize(mb->Size());
    mb->DrawNow();
  }
  else
  {
    if (iPlayed[iMode]) iPlayed[iMode]->SetText(mbuf);
    if (iPlayedDigits[iMode]) iPlayedDigits[iMode]->SetText(mbuf.Left(5));
    if (iTotalDigits[iMode]) iTotalDigits[iMode]->SetText(mbuf.Right(5));
  }
#else
  if (iPlayed[iMode]) iPlayed[iMode]->SetText(mbuf);
  if (iPlayedDigits[iMode]) iPlayedDigits[iMode]->SetText(mbuf.Left(5));
  if (iTotalDigits[iMode]) iTotalDigits[iMode]->SetText(mbuf.Right(5));
#endif
  
  SetTime(iApp->iOggPlayback->Time());
}

void
COggPlayAppView::UpdateClock(TBool forceUpdate)
{
  if (!iClock[iMode])
	  return;

  // Update the clock
  TTime now;
  now.HomeTime();
  TDateTime dtNow(now.DateTime());
  TInt clockMinute = dtNow.Minute();
  TBool clockUpdateRequired = clockMinute != iCurrentClockMinute;
  if (!clockUpdateRequired && !forceUpdate) return;

  TBuf<32> buf;
  now.FormatL(buf, KDateString);
  iClock[iMode]->SetText(buf);
  iCurrentClockMinute = clockMinute;

  if (!forceUpdate || !iAlarm[iMode])
	  return;

  // Update alarm
  TBuf<32> bufAlarm;
  if (iApp->iSettings.iAlarmActive) {
    iApp->iSettings.iAlarmTime.FormatL(bufAlarm, KDateString);
  }
  iAlarm[iMode]->SetText(bufAlarm);
}

void
COggPlayAppView::UpdateVolume()
{
  if (iVolume[iMode]) iVolume[iMode]->SetValue(iApp->iVolume);
}

void COggPlayAppView::UpdatePlaying()
{
  if (iTitle[iMode]) {
    if (iApp->iOggPlayback->Title().Length()==0)
        {
        #if defined(UIQ)
            iTitle[iMode]->SetText(iApp->iOggPlayback->FileName());
        #else
            // Series 60 : Show only the filename. (space consideration)
            TParsePtrC p(iApp->iOggPlayback->FileName());
            iTitle[iMode]->SetText( p.NameAndExt() );
        #endif
        }
    else if(!iArtist[iMode]) { // smelly code ahead
      _LIT(KSeparator," - ");
      TInt length=KSeparator().Length()+iApp->iOggPlayback->Title().Length()+iApp->iOggPlayback->Artist().Length();
      HBufC* text = HBufC::NewL(length);
      text->Des().Copy(iApp->iOggPlayback->Artist());
      text->Des().Append(KSeparator);
      text->Des().Append(iApp->iOggPlayback->Title());
      iTitle[iMode]->SetText(*text);
      delete text;
    } else {
      iTitle[iMode]->SetText(iApp->iOggPlayback->Title());
    }
  }
  if (iAlbum[iMode]) iAlbum[iMode]->SetText(iApp->iOggPlayback->Album());
  if (iArtist[iMode]) iArtist[iMode]->SetText(iApp->iOggPlayback->Artist());
  if (iGenre[iMode]) iGenre[iMode]->SetText(iApp->iOggPlayback->Genre());
  if (iTrackNumber[iMode]) iTrackNumber[iMode]->SetText(iApp->iOggPlayback->TrackNumber());

  if (iPlaying[iMode]) 
    iPlaying[iMode]->MakeVisible(iApp->iOggPlayback->State()==CAbsPlayback::EPlaying);

  if (iPaused[iMode]) {
    if (iApp->iOggPlayback->State()==CAbsPlayback::EPaused)
      iPaused[iMode]->Blink();
    else
      iPaused[iMode]->Hide();
  }

  if (iLogo[iMode])
    iLogo[iMode]->MakeVisible(iApp->iOggPlayback->FileName().Length()==0);
}

void COggPlayAppView::SetAlarm()
{
  TTime now;
  now.HomeTime();

  // Sync the alarm time to the current day
  iApp->iSettings.iAlarmTime += now.DaysFrom(iApp->iSettings.iAlarmTime);
  if (now>=iApp->iSettings.iAlarmTime)
	iApp->iSettings.iAlarmTime += TTimeIntervalDays(1);

  if (iApp->iSettings.iAlarmActive)
  {
    TBuf<128> buft;
    iApp->iSettings.iAlarmTime.FormatL(buft, KDateString);
    if (iAlarm[iMode]) iAlarm[iMode]->SetText(buft);
    if (iAlarmIcon[iMode]) iAlarmIcon[iMode]->Show();

	iAlarmTimer->At(iApp->iSettings.iAlarmTime);
  } 
  else
  {
    ClearAlarm();
	iAlarmTimer->Cancel();
  }
}

void COggPlayAppView::SnoozeAlarm()
{
  TTime now;
  now.HomeTime();

  // Add the snooze time to the current time
  iApp->iSettings.iAlarmTime = now;
  iApp->iSettings.iAlarmTime += TTimeIntervalMinutes(KSnoozeTime[iApp->iSettings.iAlarmSnooze]);

  if (iApp->iSettings.iAlarmActive)
  {
    TBuf<256> buft;
    iApp->iSettings.iAlarmTime.FormatL(buft, KDateString);
    if (iAlarm[iMode]) iAlarm[iMode]->SetText(buft);
    if (iAlarm[iMode]) iAlarm[iMode]->MakeVisible(ETrue);
    if (iAlarmIcon[iMode]) iAlarmIcon[iMode]->Show();

	iAlarmTimer->At(iApp->iSettings.iAlarmTime);
  } 
  else
  {
    ClearAlarm();
	iAlarmTimer->Cancel();
  }
}
void COggPlayAppView::ClearAlarm()
{
  if (iAlarmIcon[iMode]) iAlarmIcon[iMode]->Hide();
}

TInt
COggPlayAppView::CountComponentControls() const
{
  return iControls->Count();
}

CCoeControl*
COggPlayAppView::ComponentControl(TInt aIndex) const
{
  return iControls->At(aIndex);
}

void
COggPlayAppView::HandleControlEventL(CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/)
{
}


TKeyResponse
COggPlayAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
#if defined(SERIES60) || defined(SERIES80)
  enum EOggKeys {
    EOggConfirm=EKeyDevice3
  };
  enum EOggScancodes {
    EOggUp=EStdKeyUpArrow,
    EOggDown=EStdKeyDownArrow,
    EOggRight=EStdKeyRightArrow,
    EOggLeft=EStdKeyLeftArrow
    };

  // Utilities
  TInt code = aKeyEvent.iCode;
  TInt index = iListBox[iMode]->CurrentItemIndex();

  COggControl* c=iFocusControlsIter;
  if (code==0 && aType==EEventKeyDown) { 
    TInt scanCode = aKeyEvent.iScanCode;
    switch (scanCode)
    {
    	case EStdKeyDevice6:
			scanCode = EOggLeft; //S80 joystick
    	    break;

    	case EStdKeyDevice7:
#if defined(SERIES90)
			code = EOggConfirm; // S90 joystick, apparently!
#else
			scanCode = EOggRight; // S80 joystick
#endif
    	    break;

    	case EStdKeyDevice8:
			scanCode = EOggUp;   //S80 joystick
    	    break;

    	case EStdKeyDevice9:
			scanCode = EOggDown; //S80 joystick
    		break;

    	case EStdKeyDeviceA:
			code = EOggConfirm; //S80 joystick
    	    break;
    }
    if(iFocusControlsPresent && scanCode==EOggLeft) {
      SetPrevFocus();
      return EKeyWasConsumed;
    } else if (iFocusControlsPresent && scanCode==EOggRight) {
      SetNextFocus();
      return EKeyWasConsumed;
    } else {
      if(c==iListBox[iMode] || !iFocusControlsPresent) {
        if (scanCode==EOggDown) {
          SelectItem(index+1);
          return EKeyWasConsumed;
        } else if (scanCode==EOggUp ) {
          SelectItem(index-1);
          return EKeyWasConsumed;
        } 
      } 
      if(   (c==iVolume[iMode] && (scanCode==EOggUp || scanCode==EOggDown))
         || (!iFocusControlsPresent && (scanCode==EOggLeft || scanCode==EOggRight))
        ) {
        if(iApp->iOggPlayback->State()==CAbsPlayback::EPlaying) {
          if (scanCode==EOggUp || scanCode==EOggRight)  {
            iApp->iVolume+= KStepVolume;
          } else  if (scanCode==EOggDown || scanCode==EOggLeft) {
            iApp->iVolume-= KStepVolume;
          }
          if (iApp->iVolume>KMaxVolume) iApp->iVolume = KMaxVolume;
          if (iApp->iVolume<0) iApp->iVolume = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -