Author: titmuss
Date: Tue Jan 22 13:57:48 2008
New Revision: 1565

URL: http://svn.slimdevices.com?rev=1565&root=Jive&view=rev
Log:
 [EMAIL PROTECTED] (orig r1550):  titmuss | 2008-01-22 14:28:27 +0000
 Bug: 6627
 Description:
 Fix now playing to tick at the correct rate:
 - Fixed Window:replace() to send events correctly when transparent popups are 
used. This 
 fixed the animation timers to start and stop correctly.
 - Fixed Now Playing to always use Player:getTrackElapsed() to get the track 
elapsed time 
 and duration.
 - Fixed Player:getTrackElapsed() to always return the correct elapsed time, 
for all play 
 modes. Added support for track rate.
 - Fixed broken encapsulation of the Player object in Now Playing applet.
 
 

Modified:
    trunk/   (props changed)
    trunk/jive/src/pkg/jive/share/applets/NowPlaying/NowPlayingApplet.lua
    trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
    trunk/jive/src/pkg/jive/share/jive/slim/Player.lua
    trunk/jive/src/pkg/jive/share/jive/ui/Window.lua

Propchange: trunk/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Tue Jan 22 13:57:48 2008
@@ -1,3 +1,3 @@
-bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:1549
+bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:1550
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/SN:1083
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/scrolling:1378

Modified: trunk/jive/src/pkg/jive/share/applets/NowPlaying/NowPlayingApplet.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/applets/NowPlaying/NowPlayingApplet.lua?rev=1565&root=Jive&r1=1564&r2=1565&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/applets/NowPlaying/NowPlayingApplet.lua 
(original)
+++ trunk/jive/src/pkg/jive/share/applets/NowPlaying/NowPlayingApplet.lua Tue 
Jan 22 13:57:48 2008
@@ -113,7 +113,7 @@
        return artworkUri
 end
 
-local function SecondsToString(seconds)
+local function _secondsToString(seconds)
        local min = math.floor(seconds / 60)
        local sec = math.floor(seconds - (min*60))
 
@@ -164,7 +164,6 @@
 
        jnt:subscribe(self)
        self.player = {}
-       self.player.playerStatus = {}
        self['browse'] = {}
        self['ss'] = {}
 
@@ -177,8 +176,7 @@
        if not thisPlayer then return end
 
        self.player = player
-       -- make sure we've got the playerStatus data
-       self.player.playerStatus = player:getPlayerStatus()
+       local playerStatus = player:getPlayerStatus()
 
        -- if windowStyle hasn't been initialized yet, skip this
        if windowStyle then
@@ -193,7 +191,7 @@
                end
                self[windowStyle].window = window
 
-               if player.playerStatus and player.playerStatus.item_loop
+               if playerStatus and playerStatus.item_loop
                        and self.nowPlaying ~= nowPlaying
                then
                        -- for remote streams, nowPlaying = text
@@ -201,7 +199,7 @@
                        self.nowPlaying = nowPlaying
        
                        --update everything
-                       self:_updateAll(player.playerStatus, self[windowStyle])
+                       self:_updateAll(self[windowStyle])
 
                end
        end
@@ -209,15 +207,12 @@
 
 function notify_playerModeChange(self, player, mode)
 
-       if not self.player then return end
+       if not self.player then
+               return
+       end
 
        log:debug("Player mode has been changed to: ", mode)
-
-       self.player.mode = mode
-       self.player.playerStatus = self.player:getPlayerStatus()
-
        self:_updateMode(mode)
-
 end
 
 function notify_playerCurrent(self, player)
@@ -230,7 +225,6 @@
        if not self.player then
                return
        end
-       self.player.playerStatus = self.player:getPlayerStatus()
 
        windowStyle = 'ss'
 
@@ -256,9 +250,9 @@
                self.player = discovery:getCurrentPlayer()
        end
 
-       if player.id ~= self.player.id then
+       if player.id ~= self.player:getId() then
                log:warn("notification was not for this player")
-               log:warn("notification: ", player.id, "your player: ", 
self.player.id)
+               log:warn("notification: ", player:getId(), "your player: ", 
self.player:getId())
                return false
        else
                return true
@@ -266,18 +260,12 @@
        
 end
 
-function _updateAll(self, playerStatus, ws)
+function _updateAll(self, ws)
 
        if not ws then ws = self[windowStyle] end
        if not ws then return end
 
-       if not playerStatus then 
-               playerStatus = self.player.playerStatus 
-       end
-       -- unlikely we'll ever hit this, but it can't hurt
-       if self.player and not playerStatus then
-               playerStatus = self.player:getPlayerStatus()
-       end
+       local playerStatus = self.player:getPlayerStatus()
 
        if playerStatus.item_loop then
                local text = playerStatus.item_loop[1].text
@@ -325,20 +313,12 @@
        if not self.player then
                return
        end
-       if not self.player.playerStatus then
-               self.player.playerStatus = self.player:getPlayerStatus()
-       end
-
-       self.player.trackPos = tonumber(data.time)
-       self.player.trackLen = tonumber(data.duration)
-
-       if self.player and self.player.playerStatus and self.player.mode == 
'play' then
-               self.player.trackPos = self.player:getTrackElapsed(data)
-       end
+
+       local elapsed, duration = self.player:getTrackElapsed()
 
        if ws.progressSlider then
-               if self.player.trackLen and self.player.trackLen > 0 then
-                       ws.progressSlider:setRange(0, self.player.trackLen, 
self.player.trackPos)
+               if duration and duration > 0 then
+                       ws.progressSlider:setRange(0, duration, elapsed)
                else 
                        -- If 0 just set it to 100
                        ws.progressSlider:setRange(0, 100, 0)
@@ -350,27 +330,28 @@
 end
 
 function _updatePosition(self)
-
        if not ws then ws = self[windowStyle] end
-       if not self.player then return end
+       if not self.player then
+               return
+       end
 
        local strElapsed = ""
        local strRemain = ""
        local pos = 0
 
-       if self.player.trackPos then
-               strElapsed = SecondsToString(self.player.trackPos)
-       end
-
-       if self.player.trackLen and self.player.trackLen > 0 then
-               strRemain = "-" .. SecondsToString(self.player.trackLen - 
self.player.trackPos)
-               pos = self.player.trackPos
+       local elapsed, duration = self.player:getTrackElapsed()
+
+       if elapsed then
+               strElapsed = _secondsToString(elapsed)
+       end
+       if duration and duration > 0 then
+               strRemain = "-" .. _secondsToString(duration - elapsed)
        end
 
        self[windowStyle].progressGroup:setWidgetValue("elapsed", strElapsed)
        if showProgressBar then
                self[windowStyle].progressGroup:setWidgetValue("remain", 
strRemain)
-               self[windowStyle].progressSlider:setValue(pos)
+               self[windowStyle].progressSlider:setValue(elapsed)
        end
 end
 
@@ -399,18 +380,6 @@
        end
 end
 
-function tick(self)
-       if not self.player or self.player.mode ~= "play" then
-               return
-       end
-
-       self.player.trackPos = self.player.trackPos + 1
-       if self.player.trackLen and self.player.trackLen > 0 then
-               if self.player.trackPos > self.player.trackLen then 
self.player.trackPos = self.player.trackLen end
-       end
-
-       _updatePosition(self)
-end
 
 
-----------------------------------------------------------------------------------------
 -- Settings
@@ -447,7 +416,7 @@
                                windowStyle = 'ss'
                        end
 
-                       self:_updateAll(self.player.playerStatus, 
self[windowStyle])
+                       self:_updateAll(self[windowStyle])
 
                        return EVENT_UNUSED
                end
@@ -487,8 +456,9 @@
                window:setShowFrameworkWidgets(false)
        end
 
-       if self.player.playerStatus then
-               if not self.player.playerStatus.duration then
+       local playerStatus = self.player:getPlayerStatus()
+       if playerStatus then
+               if not playerStatus.duration then
                        showProgressBar = false
                else
                        showProgressBar = true
@@ -520,7 +490,7 @@
        
        if showProgressBar then
                self[windowStyle].progressSlider = Slider(components.progressB, 
0, 100, 0)
-               self[windowStyle].progressSlider:addTimer(1000, function() 
self:tick() end)
+               self[windowStyle].progressSlider:addTimer(1000, function() 
self:_updatePosition() end)
 
                self[windowStyle].progressGroup = Group(components.progress, {
                                              elapsed = Label("text", ""),
@@ -531,7 +501,7 @@
                self[windowStyle].progressGroup = Group(components.progressNB, {
                                              elapsed = Label("text", "")
                                      })
-               self[windowStyle].progressGroup:addTimer(1000, function() 
self:tick() end)
+               self[windowStyle].progressGroup:addTimer(1000, function() 
self:_updatePosition() end)
        end
 
        self[windowStyle].artwork = Icon("artwork")
@@ -560,11 +530,14 @@
 
 function openScreensaver(self, style, transition)
 
+       local playerStatus = self.player and self.player:getPlayerStatus()
+
+       log:warn("player=", self.player, " status=", playerStatus)
+
        -- playlist_tracks needs to be > 0 or else defer back to SlimBrowser
-       if not self.player 
-               or not self.player.playerStatus 
-                       or not self.player.playerStatus.playlist_tracks 
-                               or self.player.playerStatus.playlist_tracks == 
0 then
+       if not self.player or not playerStatus 
+                       or not playerStatus.playlist_tracks 
+                       or playerStatus.playlist_tracks == 0 then
                local browser = appletManager:getAppletInstance("SlimBrowser")
                browser:showPlaylist()
                return
@@ -573,10 +546,9 @@
        -- ss and browse
 
        --convenience
-       local _statusData = self.player.playerStatus
        local _thisTrack
-       if _statusData.item_loop then
-               _thisTrack = _statusData.item_loop[1]
+       if playerStatus.item_loop then
+               _thisTrack = playerStatus.item_loop[1]
        end
 
        if not style then style = 'ss' end
@@ -607,27 +579,27 @@
        -- if we have data, then update and display it
        if _thisTrack then
                local text = _thisTrack.text
-               if _statusData.remote == 1 and type(_statusData.current_title) 
== 'string' then
-                       text = text .. "\n" .. _statusData.current_title
-               end
-
-               _getIcon(self, _thisTrack, self[windowStyle].artwork, 
_statusData.remote)
-               self:_updateMode(_statusData.mode)
+               if playerStatus.remote == 1 and 
type(playerStatus.current_title) == 'string' then
+                       text = text .. "\n" .. playerStatus.current_title
+               end
+
+               _getIcon(self, _thisTrack, self[windowStyle].artwork, 
playerStatus.remote)
+               self:_updateMode(playerStatus.mode)
                self:_updateTrack(text)
-               self:_updateProgress(_statusData)
-               self:_updatePlaylist(true, 
self.player.playerStatus.playlist_cur_index, 
self.player.playerStatus.playlist_tracks)
+               self:_updateProgress(playerStatus)
+               self:_updatePlaylist(true, playerStatus.playlist_cur_index, 
playerStatus.playlist_tracks)
 
                -- preload artwork for next track
-               if _statusData.item_loop[2] then
-                       _getIcon(self, _statusData.item_loop[2], 
Icon("artwork"), _statusData.remote)
+               if playerStatus.item_loop[2] then
+                       _getIcon(self, playerStatus.item_loop[2], 
Icon("artwork"), playerStatus.remote)
                end
 
        -- otherwise punt
        else
                -- FIXME: we should probably exit the window when there's no 
track to display
-               _getIcon(self, nil, self.player.playerStatus.artwork, nil) 
+               _getIcon(self, nil, playerStatus.artwork, nil) 
                self:_updateTrack("\n\n\n")
-               self:_updateMode(_statusData.mode)
+               self:_updateMode(playerStatus.mode)
                self:_updatePlaylist(false, 0, 0)       
        end
 
@@ -635,7 +607,7 @@
        self[windowStyle].window:show(transitionOn)
        -- install some listeners to the window after it's shown
        self:_installListeners(self[windowStyle].window)
-       self:_updateAll(self.player.playerStatus, self[windowStyle])
+       self:_updateAll(self[windowStyle])
 
 end
 

Modified: 
trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=1565&root=Jive&r1=1564&r2=1565&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua 
(original)
+++ trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua Tue 
Jan 22 13:57:48 2008
@@ -1701,7 +1701,8 @@
 
                -- current playlist should select currently playing item 
                -- if there is only one item in the playlist, bring the 
selected item to top
-               local playlistSize = _safeDeref(_player, 'playerStatus', 
'playlist_tracks')
+               -- BUG! breaks player encapsualtion
+               local playlistSize = _safeDeref(_player, 'state', 
'playlist_tracks')
                if playlistSize == 0 then
                        
_statusStep.window:setTitle(_string("SLIMBROWSER_NOW_PLAYING"))
                end
@@ -1745,7 +1746,8 @@
                                _statusStep.window:checkLayout()
                                -- a menu size of 3 means a single item 
playlist (1 track plus clear/save playlist items)
                                -- single item playlists are skipped into the 
songinfo window
-                               local playlistSize = _safeDeref(_player, 
'playerStatus', 'playlist_tracks')
+                               -- BUG! breaks player encapsulation
+                               local playlistSize = _safeDeref(_player, 
'state', 'playlist_tracks')
                                if playlistSize == 1 then
                                        -- need to spoof a key press here to 
descend one window further
                                        
_statusStep.menu:dispatchNewEvent(EVENT_ACTION)

Modified: trunk/jive/src/pkg/jive/share/jive/slim/Player.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/jive/slim/Player.lua?rev=1565&root=Jive&r1=1564&r2=1565&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/jive/slim/Player.lua (original)
+++ trunk/jive/src/pkg/jive/share/jive/slim/Player.lua Tue Jan 22 13:57:48 2008
@@ -162,7 +162,7 @@
 -- sends notifications when a change occurs to the currently playing track
 local function _setPlayerTrackChange(self, nowPlaying, data)
        log:debug("_setPlayerTrackChange")
-       self.playerStatus = data
+
        if self.nowPlaying != nowPlaying then
                self.nowPlaying = nowPlaying
                self.jnt:notify('playerTrackChange', self, nowPlaying)
@@ -273,43 +273,40 @@
 
 =head2 jive.slim.Player:getTrackElapsed()
 
-returns the amount of time elapsed on the current track
-
-=cut
---]]
-function getTrackElapsed(self, data)
-
-       local now = os.time()
-       local correction = now - data.lastSeen
-       local trackElapsed = data.time + correction
-       if correction <= 0 then
-               return data.time
+Returns the amount of time elapsed on the current track, and the track
+duration (if known). eg:
+
+  local elapsed, duration = player:getTrackElapsed()
+  local remaining
+  if duration then
+         remaining = duration - elapsed
+  end
+
+=cut
+--]]
+function getTrackElapsed(self)
+       if not self.trackTime then
+               return nil
+       end
+
+       if self.state.mode == "play" then
+               local now = os.time()
+
+               -- multiply by rate to allow for trick modes
+               self.trackCorrection = tonumber(self.state.rate) * (now - 
self.trackSeen)
+       end
+
+log:warn("C=", self.trackCorrection, " T=", self.trackTime, " D=", 
self.trackDuration, " E=", self.trackTime + self.trackCorrection)
+
+       if self.trackCorrection <= 0 then
+               return self.trackTime, self.trackDuration
        else
-               return trackElapsed
-       end
-       
-end
-
---[[
-
-=head2 jive.slim.Player:getTrackRemaining()
-
-returns the amount of time left on the current track
-
-=cut
---]]
-
-function getTrackRemaining(self)
-
-       local now = os.time()
-       local correction = now - self.lastSeen
-       if correction < 0 then
-               correction = 0
-       end
-
-       return self.duration - self.time + correction
-       
-end
+               local trackElapsed = self.trackTime + self.trackCorrection
+               return trackElapsed, self.trackDuration
+       end
+       
+end
+
 
 --[[
 
@@ -319,9 +316,8 @@
 
 =cut
 --]]
-
 function getPlayerStatus(self)
-       return self.playerStatus
+       return self.state
 end
 
 --[[
@@ -614,13 +610,15 @@
 -- processes the playerstatus data and calls associated functions for 
notification
 function _process_status(self, event)
        log:debug("Player:_process_playerstatus()")
-       
+
        -- update our cache in one go
        self.state = event.data
-       
+
        -- used for calculating getTrackElapsed(), getTrackRemaining()
-       self.lastSeen = os.time()
-       event.data.lastSeen = self.lastSeen
+       self.trackSeen = os.time()
+       self.trackCorrection = 0
+       self.trackTime = event.data.time
+       self.trackDuration = event.data.duration
 
        _setConnected(self, self.state["player_connected"])
 
@@ -678,6 +676,9 @@
        log:debug("Player:togglePause(", paused, ")")
 
        if paused == 'stop' or paused == 'pause' then
+               -- reset the elapsed time epoch
+               self.trackSeen = os.time()
+
                self:call({'pause', '0'})
                self.state["mode"] = 'play'
        elseif paused == 'play' then
@@ -723,6 +724,12 @@
 -- 
 function play(self)
        log:debug("Player:play()")
+
+       if self.state.mode ~= 'play' then
+               -- reset the elapsed time epoch
+               self.trackSeen = os.time()
+       end
+
        self:call({'mode', 'play'})
        self.state["mode"] = 'play'
        self:updateIconbar()

Modified: trunk/jive/src/pkg/jive/share/jive/ui/Window.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/jive/ui/Window.lua?rev=1565&root=Jive&r1=1564&r2=1565&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/jive/ui/Window.lua (original)
+++ trunk/jive/src/pkg/jive/share/jive/ui/Window.lua Tue Jan 22 13:57:48 2008
@@ -220,6 +220,7 @@
 
 Replaces toReplace window with a new window object
 
+
 =cut
 --]]
 
@@ -230,7 +231,20 @@
                        if i == topWindow then
                                self:showInstead(transition)
                        else
+                               -- the old window may still be visible under
+                               -- a transparent window, if so hide it
+                               local oldwindow = Framework.windowStack[i]
+                               if oldwindow.visible then
+                                       oldwindow:dispatchNewEvent(EVENT_HIDE)
+                               end
+
                                Framework.windowStack[i] = self
+
+                               -- if the old window was visible, the new one
+                               -- is now 
+                               if oldwindow.visible then
+                                       self:dispatchNewEvent(EVENT_SHOW)
+                               end
                        end
                end
        end

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins

Reply via email to