qtmobility/plugins/multimedia/symbian/mediaplayer/s60mediaplayercontrol.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 
       
     2 /****************************************************************************
       
     3 **
       
     4 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     5 ** All rights reserved.
       
     6 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     7 **
       
     8 ** This file is part of the Qt Mobility Components.
       
     9 **
       
    10 ** $QT_BEGIN_LICENSE:LGPL$
       
    11 ** No Commercial Usage
       
    12 ** This file contains pre-release code and may not be distributed.
       
    13 ** You may use this file in accordance with the terms and conditions
       
    14 ** contained in the Technology Preview License Agreement accompanying
       
    15 ** this package.
       
    16 **
       
    17 ** GNU Lesser General Public License Usage
       
    18 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    19 ** General Public License version 2.1 as published by the Free Software
       
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    21 ** packaging of this file.  Please review the following information to
       
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    24 **
       
    25 ** In addition, as a special exception, Nokia gives you certain additional
       
    26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    28 **
       
    29 ** If you have questions regarding the use of this file, please contact
       
    30 ** Nokia at qt-info@nokia.com.
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 **
       
    39 ** $QT_END_LICENSE$
       
    40 **
       
    41 ****************************************************************************/
       
    42 
       
    43 #include "s60mediaplayercontrol.h"
       
    44 #include "s60mediaplayersession.h"
       
    45 
       
    46 #include <QtCore/qdir.h>
       
    47 #include <QtCore/qurl.h>
       
    48 #include <QtCore/qdebug.h>
       
    49 
       
    50 S60MediaPlayerControl::S60MediaPlayerControl(MS60MediaPlayerResolver& mediaPlayerResolver, QObject *parent)
       
    51     : QMediaPlayerControl(parent),
       
    52       m_mediaPlayerResolver(mediaPlayerResolver),
       
    53       m_session(NULL),
       
    54       m_stream(NULL)
       
    55 {
       
    56 }
       
    57 
       
    58 S60MediaPlayerControl::~S60MediaPlayerControl()
       
    59 {
       
    60 }
       
    61 
       
    62 qint64 S60MediaPlayerControl::position() const
       
    63 {
       
    64     if (m_session)
       
    65         return m_session->position();
       
    66     return 0;
       
    67 }
       
    68 
       
    69 qint64 S60MediaPlayerControl::duration() const
       
    70 {
       
    71     if (m_session)
       
    72         return m_session->duration();
       
    73     return -1;
       
    74 }
       
    75 
       
    76 QMediaPlayer::State S60MediaPlayerControl::state() const
       
    77 {
       
    78     if (m_session)
       
    79         return m_session->state();
       
    80     return QMediaPlayer::StoppedState;
       
    81 }
       
    82 
       
    83 QMediaPlayer::MediaStatus S60MediaPlayerControl::mediaStatus() const
       
    84 {   
       
    85     if (m_session)
       
    86         return m_session->mediaStatus();
       
    87     return QMediaPlayer::NoMedia;
       
    88 }
       
    89 
       
    90 int S60MediaPlayerControl::bufferStatus() const
       
    91 {
       
    92     return -1;
       
    93 }
       
    94 
       
    95 int S60MediaPlayerControl::volume() const
       
    96 {
       
    97     if (m_session)
       
    98         return m_session->volume();
       
    99     return m_mediaSettings.volume();
       
   100 }
       
   101 
       
   102 bool S60MediaPlayerControl::isMuted() const
       
   103 {
       
   104    if (m_session)
       
   105        return  m_session->isMuted();
       
   106    return m_mediaSettings.isMuted();
       
   107 }
       
   108 
       
   109 bool S60MediaPlayerControl::isSeekable() const
       
   110 {
       
   111     if (m_session)
       
   112        return  m_session->isSeekable();
       
   113     return false;
       
   114 }
       
   115 
       
   116 QMediaTimeRange S60MediaPlayerControl::availablePlaybackRanges() const
       
   117 {
       
   118     QMediaTimeRange ranges;
       
   119 
       
   120     if(m_session && m_session->isSeekable())
       
   121         ranges.addInterval(0, m_session->duration());
       
   122 
       
   123     return ranges;
       
   124 }
       
   125 
       
   126 qreal S60MediaPlayerControl::playbackRate() const
       
   127 {
       
   128     //None of symbian players supports this.
       
   129     return m_mediaSettings.playbackRate();
       
   130 }
       
   131 
       
   132 void S60MediaPlayerControl::setPlaybackRate(qreal rate)
       
   133 {
       
   134     //None of symbian players supports this.
       
   135     m_mediaSettings.setPlaybackRate(rate);
       
   136     emit playbackRateChanged(playbackRate());
       
   137     
       
   138 }
       
   139 
       
   140 void S60MediaPlayerControl::setPosition(qint64 pos)
       
   141 {
       
   142     if (m_session)
       
   143         m_session->setPosition(pos);
       
   144 }
       
   145 
       
   146 void S60MediaPlayerControl::play()
       
   147 {
       
   148     if (m_session)
       
   149         m_session->play();
       
   150 }
       
   151 
       
   152 void S60MediaPlayerControl::pause()
       
   153 {
       
   154     if (m_session)
       
   155         m_session->pause();
       
   156 }
       
   157 
       
   158 void S60MediaPlayerControl::stop()
       
   159 {
       
   160     if (m_session)
       
   161         m_session->stop();
       
   162 }
       
   163 
       
   164 void S60MediaPlayerControl::setVolume(int volume)
       
   165 {
       
   166     int boundVolume = qBound(0, volume, 100);
       
   167     if (boundVolume == m_mediaSettings.volume())
       
   168         return;
       
   169     
       
   170     m_mediaSettings.setVolume(boundVolume);
       
   171     if (m_session)
       
   172         m_session->setVolume(boundVolume);
       
   173 
       
   174     emit volumeChanged(boundVolume);
       
   175 }
       
   176 
       
   177 void S60MediaPlayerControl::setMuted(bool muted)
       
   178 {
       
   179     if (m_mediaSettings.isMuted() == muted)
       
   180         return;
       
   181     
       
   182     m_mediaSettings.setMuted(muted);
       
   183     if (m_session)
       
   184         m_session->setMuted(muted);
       
   185     
       
   186     emit mutedChanged(muted);
       
   187 }
       
   188 
       
   189 QMediaContent S60MediaPlayerControl::media() const
       
   190 {
       
   191     return m_currentResource;
       
   192 }
       
   193 
       
   194 const QIODevice *S60MediaPlayerControl::mediaStream() const
       
   195 {
       
   196     return m_stream;
       
   197 }
       
   198 
       
   199 void S60MediaPlayerControl::setMedia(const QMediaContent &source, QIODevice *stream)
       
   200 {
       
   201     Q_UNUSED(stream)
       
   202     // we don't want to set & load media again when it is already loaded    
       
   203     if (m_session && m_currentResource == source && m_session->state() == QMediaPlayer::LoadedMedia)
       
   204         return;
       
   205 
       
   206     if (source.isNull())
       
   207         return;
       
   208     
       
   209     // store to variable as session is created based on the content type.
       
   210     m_currentResource = source;
       
   211     if (m_session)
       
   212         m_session->stop();
       
   213     
       
   214     S60MediaPlayerSession *newSession = m_mediaPlayerResolver.PlayerSession(); 
       
   215 
       
   216     m_session = newSession;
       
   217     
       
   218     if (m_session) {
       
   219         QUrl url = source.canonicalUrl();
       
   220         
       
   221         if (m_session->mediaFileLocal())
       
   222             m_session->load(url);	
       
   223         else
       
   224             m_session->loadUrl(url);
       
   225             
       
   226         emit mediaChanged(m_currentResource);
       
   227     } else {
       
   228         emit error(QMediaPlayer::FormatError, QString("Symbian: -5"));
       
   229         emit mediaStatusChanged(QMediaPlayer::InvalidMedia);
       
   230     }
       
   231 }
       
   232 
       
   233 void S60MediaPlayerControl::setVideoOutput(QObject *output)
       
   234 {
       
   235     if (!m_session)
       
   236         m_session = m_mediaPlayerResolver.VideoPlayerSession();
       
   237     m_session->setVideoRenderer(output);
       
   238 }
       
   239 
       
   240 bool S60MediaPlayerControl::isAudioAvailable() const
       
   241 {
       
   242     if (m_session)
       
   243         return m_session->isAudioAvailable(); 
       
   244     return false;
       
   245 }
       
   246 
       
   247 bool S60MediaPlayerControl::isVideoAvailable() const
       
   248 {
       
   249     if (m_session)
       
   250         return m_session->isVideoAvailable();
       
   251     return false;
       
   252 }
       
   253 
       
   254 const S60MediaSettings& S60MediaPlayerControl::mediaControlSettings() const
       
   255 {
       
   256     return m_mediaSettings;
       
   257 }