[gnome-music] initial gstreamer configuration



commit a8e76c159800b2f845d17529d5cd8b2d37c049ca
Author: Eslam Mostafa <cseslam gmail com>
Date:   Wed Apr 3 14:29:42 2013 +0200

    initial gstreamer configuration
    
    Signed-off-by: Seif Lotfy <seif lotfy com>

 src/application.js |    5 +--
 src/player.js      |   64 +++++++++++++++++++++++++++++++++++++++++++++------
 src/view.js        |   24 +++++++++++++-----
 src/widgets.js     |   29 +++++++++++++---------
 src/window.js      |    8 +++---
 5 files changed, 96 insertions(+), 34 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 79f2b91..4445eb1 100644
--- a/src/application.js
+++ b/src/application.js
@@ -76,12 +76,11 @@ const Application = new Lang.Class({
         Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
                                                  provider,
                                                  Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
-
-        this._window = new Window.MainWindow(this);
-        this._buildAppMenu();
     },
     
     vfunc_activate: function() {
+        this._window = new Window.MainWindow(this);
+        this._buildAppMenu();
         this._window.present();
     },
 });
diff --git a/src/player.js b/src/player.js
index 64837ce..a21e938 100644
--- a/src/player.js
+++ b/src/player.js
@@ -46,21 +46,69 @@ const PlayPauseButton = new Lang.Class({
 
 const Player = new Lang.Class({
     Name: "Player",
-    //Extends: GLib.Object,
 
-    _init: function(playlist) {
-        this.playlist = playlist;
+    _init: function() {
+        this.playlist = [];
+        this.currentTrack = 0;
         this.cache = AlbumArtCache.AlbumArtCache.getDefault();
 
-        //Gst.init(null, 0);
-        //this.source = new Gst.ElementFactory.make("audiotestrc", "source");
-        //this.sink = new Gst.ElementFactory.make("autoaudiosink", "output");
-        //this.playbin = new Gst.ElementFactory.make("playbin", "playbin");
-        //this.bus = this.playbin.get_bus();
+        Gst.init(null, 0);
+        this.player = Gst.ElementFactory.make("playbin", "player");
+        this.bus = this.player.get_bus();
+        this.msg = this.bus.timed_pop_filtered (Gst.Clock.TIME_NONE, Gst.Message.ERROR | Gst.Message.EOS);
 
         this._setup_view();
     },
 
+    setUri: function(uri) {
+        this.player.set_property("uri", uri);
+    },
+
+    play: function() {
+        this.stop();
+        this._setDuration(this.playlist[this.currentTrack].get_duration());
+        this.setUri(this.playlist[this.currentTrack].get_url());
+        this.player.set_state(Gst.State.PLAYING);
+        this.progress_scale.set_sensitive(true);
+        //this.play_btn.setPauseMode();
+        var value = this.progress_scale.get_value();
+        Mainloop.timeout_add(1000, Lang.bind(this, function () {
+            value = this.progress_scale.get_value();
+            this.progress_scale.set_value(value+1);
+            return true;
+        })); 
+    },
+
+    pause: function () {
+        this.progress_scale.set_sensitive(false);
+        //this.play_btn.setPauseMode();
+    },
+    
+    stop: function() {
+        this.player.set_state(Gst.State.NULL);
+    },
+
+    appendToPlaylist: function (track) {
+        this.playlist.push(track);
+    },
+
+    playNext: function () {
+        this.currentTrack = this.currentTrack + 1;
+        this.play();
+    },
+
+    setPlaylist: function (playlist) {
+        this.playlist = playlist;
+    },
+
+    setCurrentTrack: function (track) {
+        for(let t in this.playlist) {
+            if(this.playlist[t].get_url() == track.get_url()) {
+                this.currentTrack = t;
+            }
+        }
+    },
+
     _setup_view: function() {
         var alignment,
             artist_lbl,
diff --git a/src/view.js b/src/view.js
index b22591e..0fd65c9 100644
--- a/src/view.js
+++ b/src/view.js
@@ -276,11 +276,11 @@ const Albums = new Lang.Class({
     Name: "AlbumsView",
     Extends: ViewContainer,
 
-    _init: function(header_bar){
+    _init: function(header_bar, player){
         this.parent("Albums", header_bar);
         this.view.set_view_type(Gd.MainViewType.ICON);
         this.countQuery = Query.album_count;
-        this._albumWidget = new Widgets.AlbumWidget ();
+        this._albumWidget = new Widgets.AlbumWidget (player);
         this.add(this._albumWidget)
         this.header_bar.setState (1);
     },
@@ -315,16 +315,26 @@ const Songs = new Lang.Class({
     Name: "SongsView",
     Extends: ViewContainer,
 
-    _init: function(header_bar) {
+    _init: function(header_bar, player) {
         this.parent("Songs", header_bar);
         this.countQuery = Query.songs_count;
         this._items = {};
         this.view.set_view_type(Gd.MainViewType.LIST);
-        this._iconHeight = 32
-        this._iconWidth = 32
+        this._iconHeight = 32;
+        this._iconWidth = 32;
         this._addListRenderers();
     },
 
+    _onItemActivated: function (widget, id, path) {
+        var iter = this._model.get_iter (path)[1];
+        var item = this._model.get_value (iter, 5);
+
+        this.player.stop();
+        this.player.setUri(item.get_url());
+        this.player.setDuration(item.get_duration());
+        this.player.play();
+    },
+
     _addListRenderers: function() {
         let listWidget = this.view.get_generic_view();
 
@@ -368,7 +378,7 @@ const Playlists = new Lang.Class({
     Name: "PlaylistsView",
     Extends: ViewContainer,
 
-    _init: function(header_bar) {
+    _init: function(header_bar, player) {
         this.parent("Playlists", header_bar);
     },
 });
@@ -377,7 +387,7 @@ const Artists = new Lang.Class({
     Name: "ArtistsView",
     Extends: ViewContainer,
 
-    _init: function(header_bar) {
+    _init: function(header_bar, player) {
         this.parent("Artists", header_bar);
     },
 });
diff --git a/src/widgets.js b/src/widgets.js
index ee794b4..609b1a2 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -33,7 +33,7 @@ const albumArtCache = AlbumArtCache.AlbumArtCache.getDefault();
 const ClickableLabel = new Lang.Class({
     Name: "ClickableLabel",
     Extends: Gtk.Box,
-    
+
     _init: function (track) {
         this.parent();
         this.track = track
@@ -53,7 +53,7 @@ const ClickableLabel = new Lang.Class({
             time = minutes + ":" + seconds;
         let length_label = new Gtk.Label({ label : time });
         length_label.set_alignment(1.0, 0.5)
-        
+
         box.pack_start(label, true, true, 0);
         box.pack_end(length_label, true, true, 0);
         box.set_spacing(15)
@@ -66,21 +66,16 @@ const ClickableLabel = new Lang.Class({
         this.button.set_relief(Gtk.ReliefStyle.NONE);
         this.button.set_can_focus(false);
         this.show_all();
-            
-        this.button.connect("clicked", Lang.bind(this, this._on_btn_clicked));
     },
-    
-    _on_btn_clicked: function(btn) {
-    },
-    
 });
 
 
 const AlbumWidget = new Lang.Class({
     Name: "AlbumWidget",
     Extends: Gtk.EventBox,
-    
-    _init: function (album) {
+
+    _init: function (player) {
+        this.player = player;
         this.hbox = new Gtk.HBox ();
         this.box = new Gtk.VBox();
         this.scrolledWindow = new Gtk.ScrolledWindow();
@@ -158,11 +153,21 @@ const AlbumWidget = new Lang.Class({
             this.songsList.remove(children[i]);
         }
         this.tracks_labels = {};
+        var tracks = [];
         grilo.getAlbumSongs(item.get_id(), Lang.bind(this, function (source, prefs, track) {
             if (track != null) {
+                tracks.push(track);
                 duration = duration + track.get_duration();
-                this.songsList.pack_start(new ClickableLabel (track), false, false, 0);
-                this.running_length_label_info.set_text((parseInt(duration/60) + 1) + " min")
+                let clickableLabel = new ClickableLabel (track);
+                this.tracks_labels[track.get_title()] = clickableLabel;
+                this.songsList.pack_start(clickableLabel, false, false, 0);
+                this.running_length_label_info.set_text((parseInt(duration/60) + 1) + " min");
+                this.tracks_labels[track.get_title()].button.connect("clicked", Lang.bind(this, function () {
+                    this.player.appendToPlaylist(track);
+                    this.player.setCurrentTrack(track);
+                    this.player.play();
+                }));
+                //this.player.setPlaylist(tracks);
             }
         }));
 
diff --git a/src/window.js b/src/window.js
index b224378..526e4da 100644
--- a/src/window.js
+++ b/src/window.js
@@ -64,10 +64,10 @@ const MainWindow = new Lang.Class({
         this._box.pack_start(this.player.eventbox, false, false, 0);
         this.add(this._box);
 
-        this.views[0] = new Views.Albums(this.toolbar);
-        this.views[1] = new Views.Artists(this.toolbar);
-        this.views[2] = new Views.Songs(this.toolbar);
-        this.views[3] = new Views.Playlists(this.toolbar);
+        this.views[0] = new Views.Albums(this.toolbar, this.player);
+        this.views[1] = new Views.Artists(this.toolbar, this.player);
+        this.views[2] = new Views.Songs(this.toolbar, this.player);
+        this.views[3] = new Views.Playlists(this.toolbar, this.player);
 
         for (let i in this.views) {
             this._stack.add_titled(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]