[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [Phonon/4.1] aa759e0: two working examples to show gapless playback
From:       Matthias Kretz <kretz () kde ! org>
Date:       2011-01-02 21:59:19
Message-ID: 20110102215919.A9FFFA6300 () git ! kde ! org
[Download RAW message or body]


	A	 examples/videoplayandforget.cpp	 [License: UNKNOWN]

commit aa759e0f4f7ebd874bf9bcb76529484429640f3c
Author: Matthias Kretz <kretz@kde.org>
Date:   Tue Sep 19 10:13:22 2006 +0000

    two working examples to show gapless playback and a simple VideoPlayer usage

diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 0c9d66d..e371a1a 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,21 +1,11 @@
-
-########### next target ###############
-
-set(crossfade_SRCS crossfade.cpp )
-
+set(crossfade_SRCS crossfade.cpp)
 kde4_automoc(${crossfade_SRCS})
-
 if(KDE4_BUILD_TESTS)
-
-kde4_add_executable(crossfade ${crossfade_SRCS})
-
-target_link_libraries(crossfade  ${KDE4_KDECORE_LIBS} )
-
+  kde4_add_executable(crossfade ${crossfade_SRCS})
+  target_link_libraries(crossfade ${KDE4_KDECORE_LIBS} phononcore)
 endif(KDE4_BUILD_TESTS)
 
-########### install files ###############
-
-
-
-
-
+set(videoplayandforget_SRCS videoplayandforget.cpp)
+kde4_automoc(${videoplayandforget_SRCS})
+kde4_add_executable(videoplayandforget ${videoplayandforget_SRCS})
+target_link_libraries(videoplayandforget ${KDE4_KDECORE_LIBS} phononui)
diff --git a/examples/crossfade.cpp b/examples/crossfade.cpp
index dfa2bd0..e60a8ce 100644
--- a/examples/crossfade.cpp
+++ b/examples/crossfade.cpp
@@ -18,56 +18,72 @@
 */
 
 #include "crossfade.h"
-#include <phonon/mediaobject.h>
+#include <phonon/mediaqueue.h>
 #include <phonon/audiopath.h>
 #include <phonon/audiooutput.h>
-#include <phonon/volumefadereffect.h>
 #include <kurl.h>
 #include <QTimer>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <kapplication.h>
+#include <klocale.h>
 
-static const long CROSSFADE_TIME = 3000; // 3 seconds
-
-Crossfader::Crossfader( QObject* parent )
+Crossfader::Crossfader( const KUrl& url1, const KUrl& url2, QObject* parent )
 	: QObject( parent )
+	, media( new MediaQueue( this ) )
+	, path( new AudioPath( this ) )
+	, output( new AudioOutput( Phonon::MusicCategory, this ) )
 {
-	m1 = new MediaObject( this ); m2 = new MediaObject( this );
-	a1 = new AudioPath( this );   a2 = new AudioPath( this );
-	f1 = new VolumeFaderEffect( this ); f2 = new VolumeFaderEffect( this );
-	output = new AudioOutput( this );
-
-	m1->addAudioPath( a1 );  m2->addAudioPath( a2 );
-	a1->insertEffect( f1 );  a2->insertEffect( f2 );
-	a1->addOutput( output ); a2->addOutput( output );
-	m1->setAboutToFinishTime( CROSSFADE_TIME ); m2->setAboutToFinishTime( CROSSFADE_TIME );
-	connect( m1, SIGNAL( aboutToFinish( long ) ), SLOT( crossfade( long ) ) );
-	connect( m2, SIGNAL( aboutToFinish( long ) ), SLOT( crossfade( long ) ) );
-	connect( m1, SIGNAL( finished() ), SLOT( setupNext() ) );
-	connect( m2, SIGNAL( finished() ), SLOT( setupNext() ) );
+	media->addAudioPath( path );
+	path->addOutput( output );
+	media->setUrl( url1 );
+	media->setNextUrl( url2 );
+	connect( media, SIGNAL( finished() ), SLOT( finished() ) );
+	media->play();
+	media->seek( media->totalTime() * 97 / 100 );
+	//QTimer::singleShot( 0, media, SLOT( play() ) );
 }
 
-void Crossfader::crossfade( long fadeTime )
+void Crossfader::finished()
 {
-	f1->fadeOut( fadeTime );
-	f2->fadeIn( fadeTime );
-	m2->play();
+	static int count = 0;
+	++count;
+	if( count == 2 )
+	{
+		qApp->quit();
+	}
 }
 
-void Crossfader::setupNext()
+static const KCmdLineOptions options[] =
 {
-	qSwap( m1, m2 ); qSwap( a1, a2 ); qSwap( f1, f2 );
-	KUrl nextUrl;
-	emit needNextUrl( nextUrl );
-	m2->setUrl( nextUrl );
-}
+	{ "+URL1", I18N_NOOP( "The first URL to play" ), 0 },
+	{ "+URL2", I18N_NOOP( "The second URL to play" ), 0 },
+	KCmdLineLastOption // End of options.
+};
 
-void Crossfader::start( const KUrl& firstUrl )
+int main( int argc, char ** argv )
 {
-	m1->setUrl( firstUrl );
-	m1->play();
+	KAboutData about( "crossfade", "Phonon Crossfade Example",
+			"1.0", "",
+			KAboutData::License_LGPL, 0 );
+	about.addAuthor( "Matthias Kretz", 0, "kretz@kde.org" );
+	KCmdLineArgs::init( argc, argv, &about );
+	KCmdLineArgs::addCmdLineOptions( options );
+	KApplication app;
+	KUrl url1;
+	KUrl url2;
+	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+	if( args->count() == 2 )
+	{
+		url1 = args->url( 0 );
+		url2 = args->url( 1 );
+		if( url1.isValid() && url2.isValid() )
+		{
+			Crossfader xfader( url1, url2 );
+			return app.exec();
+		}
+	}
+	return 1;
 }
 
-void Crossfader::stop()
-{
-	f1->fadeOut( CROSSFADE_TIME );
-	QTimer::singleShot( CROSSFADE_TIME, m1, SLOT( stop() ) );
-}
+#include "crossfade.moc"
diff --git a/examples/crossfade.h b/examples/crossfade.h
index 48c4c4a..7cc4332 100644
--- a/examples/crossfade.h
+++ b/examples/crossfade.h
@@ -17,12 +17,14 @@
 
 */
 
+#ifndef CROSSFADE_H
+#define CROSSFADE_H
+
 #include <QObject>
 
 namespace Phonon {
-	class MediaObject;
+	class MediaQueue;
 	class AudioPath;
-	class VolumeFaderEffect;
 	class AudioOutput;
 }
 class KUrl;
@@ -32,22 +34,14 @@ class Crossfader : public QObject
 {
 	Q_OBJECT
 	public:
-		Crossfader( QObject* parent = 0 );
-
-	signals:
-		void needNextUrl( KUrl& nextUrl );
-
-	public slots:
-		void start( const KUrl& firstUrl );
-		void stop();
+		Crossfader( const KUrl& url1, const KUrl& url2, QObject* parent = 0 );
 
 	private slots:
-		void crossfade( long );
-		void setupNext();
+		void finished();
 
 	private:
-		MediaObject *m1, *m2;
-		AudioPath *a1, *a2;
-		VolumeFaderEffect *f1, *f2;
+		MediaQueue *media;
+		AudioPath *path;
 		AudioOutput *output;
 };
+#endif // CROSSFADE_H
diff --git a/examples/videoplayandforget.cpp b/examples/videoplayandforget.cpp
new file mode 100644
index 0000000..9942c36
--- /dev/null
+++ b/examples/videoplayandforget.cpp
@@ -0,0 +1,61 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2006 Matthias Kretz <kretz@kde.org>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License version 2 as published by the Free Software Foundation.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+
+*/
+
+#include <phonon/ui/videoplayer.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <kapplication.h>
+#include <kurl.h>
+#include <klocale.h>
+
+using namespace Phonon;
+
+static const KCmdLineOptions options[] =
+{
+	{ "+URL", I18N_NOOP( "An URL to a video" ), 0 },
+	KCmdLineLastOption // End of options.
+};
+
+int main( int argc, char ** argv )
+{
+	KAboutData about( "videoplayandforget", "Phonon VideoPlayer Example",
+			"1.0", "",
+			KAboutData::License_LGPL, 0 );
+	about.addAuthor( "Matthias Kretz", 0, "kretz@kde.org" );
+	KCmdLineArgs::init( argc, argv, &about );
+	KCmdLineArgs::addCmdLineOptions( options );
+	KApplication app;
+	KUrl url;
+	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+	if( args->count() == 1 )
+	{
+		url = args->url( 0 );
+		if( url.isValid() )
+		{
+			VideoPlayer player( Phonon::VideoCategory );
+			QObject::connect( &player, SIGNAL( finished() ), &app, SLOT( quit() ) );
+			player.show();
+			player.resize( 640, 480 );
+			player.play( url );
+			player.seek( player.totalTime() * 9 / 10 );
+			return app.exec();
+		}
+	}
+	return 1;
+}
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic