demos/qmediaplayer/mediaplayer.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the demonstration applications of the Qt Toolkit.
     7 ** This file is part of the demonstration applications of the Qt Toolkit.
     8 **
     8 **
   671     setWindowTitle(fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1));
   671     setWindowTitle(fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1));
   672     m_MediaObject.setCurrentSource(Phonon::MediaSource(fileName));
   672     m_MediaObject.setCurrentSource(Phonon::MediaSource(fileName));
   673     m_MediaObject.play();
   673     m_MediaObject.play();
   674 }
   674 }
   675 
   675 
       
   676 void MediaPlayer::setLocation(const QString& location)
       
   677 {
       
   678     setWindowTitle(location.right(location.length() - location.lastIndexOf('/') - 1));
       
   679     m_MediaObject.setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(location.toUtf8())));
       
   680     m_MediaObject.play();
       
   681 }
       
   682 
   676 bool MediaPlayer::playPauseForDialog()
   683 bool MediaPlayer::playPauseForDialog()
   677 {
   684 {
   678     // If we're running on a small screen, we want to pause the video when
   685     // If we're running on a small screen, we want to pause the video when
   679     // popping up dialogs. We neither want to tamper with the state if the
   686     // popping up dialogs. We neither want to tamper with the state if the
   680     // user has paused.
   687     // user has paused.
   848     settings.beginGroup(QLatin1String("BrowserMainWindow"));
   855     settings.beginGroup(QLatin1String("BrowserMainWindow"));
   849     QString sourceURL = settings.value("location").toString();
   856     QString sourceURL = settings.value("location").toString();
   850     bool ok = false;
   857     bool ok = false;
   851     sourceURL = QInputDialog::getText(this, tr("Open Location"), tr("Please enter a valid address here:"), QLineEdit::Normal, sourceURL, &ok);
   858     sourceURL = QInputDialog::getText(this, tr("Open Location"), tr("Please enter a valid address here:"), QLineEdit::Normal, sourceURL, &ok);
   852     if (ok && !sourceURL.isEmpty()) {
   859     if (ok && !sourceURL.isEmpty()) {
   853         setWindowTitle(sourceURL.right(sourceURL.length() - sourceURL.lastIndexOf('/') - 1));
   860         setLocation(sourceURL);
   854         m_MediaObject.setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(sourceURL.toUtf8())));
       
   855         m_MediaObject.play();
       
   856         settings.setValue("location", sourceURL);
   861         settings.setValue("location", sourceURL);
   857     }
   862     }
   858 }
   863 }
   859 
   864 
   860 /*!
   865 /*!
   890             linkFile.close();
   895             linkFile.close();
   891         }
   896         }
   892     }
   897     }
   893 
   898 
   894     if (!list.isEmpty()) {
   899     if (!list.isEmpty()) {
   895         m_MediaObject.setCurrentSource(Phonon::MediaSource(list[0]));
   900         m_MediaObject.clearQueue();
   896         m_MediaObject.play();
   901         setLocation(list[0].toString());
   897         for (int i = 1; i < list.count(); i++)
   902         for (int i = 1; i < list.count(); i++)
   898             m_MediaObject.enqueue(Phonon::MediaSource(list[i]));
   903             m_MediaObject.enqueue(Phonon::MediaSource(list[i]));
       
   904         m_MediaObject.play();
   899     }
   905     }
   900 
   906 
   901     forwardButton->setEnabled(!m_MediaObject.queue().isEmpty());
   907     forwardButton->setEnabled(!m_MediaObject.queue().isEmpty());
   902     settings.setValue("openRamFile", fileNameList[0]);
   908     settings.setValue("openRamFile", fileNameList[0]);
   903 }
   909 }