qtinternetradio/ui/inc/irplaycontroller.h
changeset 0 09774dfdd46b
child 2 2e1adbfc62af
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #ifndef IRPLAYCONTROLLER_H
       
    18 #define IRPLAYCONTROLLER_H
       
    19 
       
    20 #include <QObject>
       
    21 #include <hbglobal.h>
       
    22 
       
    23 #include "irqenums.h"
       
    24 
       
    25 class HbProgressDialog;
       
    26 class IRApplication;
       
    27 class IRQMediaPlayer;
       
    28 class IRQPreset;
       
    29 class IRQMetaData;
       
    30 class IRQSongHistoryEngine;
       
    31 class IRQStatisticsReporter;
       
    32 
       
    33 /**
       
    34  * This class is a wrapper for IRQMediaPlayer.
       
    35  */
       
    36 
       
    37 class IRPlayController : public QObject
       
    38 {
       
    39     Q_OBJECT
       
    40 
       
    41 public:
       
    42     explicit IRPlayController(IRApplication* aApplication);
       
    43     ~IRPlayController();
       
    44 
       
    45     // Play a station
       
    46     void connectToChannel(IRQPreset *aPreset, IRQConnectedFrom aConnectedFrom);
       
    47 
       
    48     // Create a buffering dialog
       
    49     void createBufferingDialog(const QObject *aReceiver, const char *aFunc);
       
    50 
       
    51     // Close the buffering dialog
       
    52     void closeBufferingDialog();
       
    53 
       
    54     // Play control methods
       
    55     void resume();
       
    56     void stop(IRQTerminatedType aStopReason);
       
    57     int getVolume() const;
       
    58     void setVolume(int aVolume);
       
    59     void enableStereo();
       
    60     void disableStereo();
       
    61 
       
    62     // Check the playing status
       
    63     bool isPlaying() const;
       
    64 
       
    65     // Check the playing status
       
    66     bool isStopped() const;
       
    67 
       
    68     // Get the preset of now playing
       
    69     IRQPreset * getNowPlayingPreset() const;
       
    70 
       
    71     // Get the meta data
       
    72     IRQMetaData * getMetaData() const;
       
    73     
       
    74     IRQTerminatedType getStopReason() const;
       
    75     
       
    76 #ifdef _DEBUG
       
    77     int bitrateTrying() const;
       
    78 #endif 
       
    79 
       
    80 signals:
       
    81     // emitted when meta data is available
       
    82     void metaDataAvailable(IRQMetaData*);
       
    83 
       
    84     // emitted when playing started
       
    85     void playingStarted();
       
    86 
       
    87     // emitted when playing stopped
       
    88     void playingStopped();
       
    89 
       
    90     // emitted when logo needs to update
       
    91     void initializeLogo();
       
    92 
       
    93 private slots:
       
    94     // slots connected with IRQMediaPlayer
       
    95     void connectionEstablished(int aBitrate);
       
    96     void errorOccured(IRQError aError);
       
    97     void updateProgress(int aProgress);
       
    98     void fetchVolume(int &aVolume);
       
    99     void handleMetaDataReceived(IRQMetaData& aIRmetaData);
       
   100 
       
   101     // slots connected with own functions
       
   102     void cancelBuffering();
       
   103     void handleError();
       
   104 
       
   105 private:
       
   106     void createNote(const QString &aNote = hbTrId("txt_irad_info_failed_to_connect"));
       
   107     void connectSignalSlot();
       
   108 
       
   109     // Play next URL if the previous failed to connect.
       
   110     bool playNextUrl();
       
   111 
       
   112     void doPlay(const QString& aUrl);
       
   113 	
       
   114 	void startSession();
       
   115 	void endSession(IRQTerminatedType aStopReason);
       
   116 
       
   117 private:
       
   118     IRApplication *iApplication;
       
   119     IRQMediaPlayer *iMediaPlayer;
       
   120     
       
   121     IRQStatisticsReporter *iStatisticsReporter;
       
   122     IRQConnectedFrom iConnectedFrom;
       
   123     bool iSessionStarted;
       
   124     bool iGetServerResult;
       
   125     
       
   126     HbProgressDialog *iBufferingDialog;
       
   127     IRQPreset *iNowPlayingPreset;
       
   128     // reference of IRQMediaPlayer meta data
       
   129     IRQMetaData *iMetaData;
       
   130     IRQSongHistoryEngine *iSongHistoryEngine;
       
   131 
       
   132     enum EPlayState
       
   133     {
       
   134         //initial state
       
   135         EStopped = 0,
       
   136         //connecting station and buffering
       
   137         EBuffering,
       
   138         //playing
       
   139         EPlaying
       
   140     };
       
   141 
       
   142     EPlayState iPlayState;
       
   143     // If resuming the last played url fails, connect to all the preset.
       
   144     bool iResuming;
       
   145 
       
   146     // variants for play next URL
       
   147     // available bitrates in the preset
       
   148     QList<int> iAvailableBitrate;
       
   149 
       
   150     // the bitrate is now tried.
       
   151     int iTryingBitrate;
       
   152 
       
   153     // the URLs of a specific bitrate
       
   154     QList<QString> *iUrlArray;
       
   155 
       
   156 #ifdef __WINS__
       
   157     QString iLastPlayedChannelName;
       
   158 #endif
       
   159 
       
   160     // the bitrate from real station feedback.
       
   161     int iRealBitrate;
       
   162     QString iLastPlayedUrl;
       
   163     // To handle error async
       
   164     IRQError iLastError;
       
   165     
       
   166     IRQTerminatedType iStopReason;
       
   167 };
       
   168 
       
   169 #endif  //IRPLAYCONTROLLER_H