def play_music(filepath):
if isinstance(filepath, str):
filepath = filepath.decode('utf-8')
url = playlist_path(filepath, stream=False)
name = os.path.basename(filepath)
listitem = xbmcgui.ListItem(name)
listitem.setInfo(type='Music', infoLabels={'Title': name})
if url:
xbmc.Player().play(url, listitem, windowed=False)
# cache the output of content menu
python类Player()的实例源码
def __init__(self, **kwargs):
self.__sp = kwargs.get("sp")
self.__spotty = kwargs.get("spotty")
self.__playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
xbmc.Player.__init__(self, **kwargs)
threading.Thread.__init__(self)
self.setDaemon(True)
def play_connect(self):
'''start local connect playback - called from webservice when local connect player starts playback'''
playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
cur_playback = self.sp.current_playback()
trackdetails = cur_playback["item"]
url, li = parse_spotify_track(trackdetails, silenced=False, is_connect=True)
playlist.clear()
playlist.add(url, li)
playlist.add("http://localhost:%s/nexttrack" % PROXY_PORT)
player = xbmc.Player()
player.play(playlist)
del playlist
del player
def play(self, *args, **kwds):
self._pl = xbmc.PlayList(0)
self._pl.clear()
self._source = SpotifyRadioTrackBuffer(self._seed_tracks)
self._source.start()
xbmc.executebuiltin('XBMC.RandomOff')
xbmc.executebuiltin('XBMC.RepeatOff')
for _i in range(2):
self._add_to_playlist()
xbmc.Player.play(self, self._pl)
def onPlayBackEnded(self):
xbmc.Player.onPlayBackEnded(self)
def onPlayBackStopped(self):
self._source.stop()
self._pl.clear()
xbmc.Player.onPlayBackStopped(self)
def __init__( self, *args, **kwargs ):
xbmc.Player.__init__( self )
self.isExit = False
self.seek = 0
self.package = None
self.time = 0
self.service = None
self.current = 1
self.playStatus = False
self.currentURL = ''
def __init__ (self):
xbmc.Player.__init__(self)
def __init__( self, *args, **kwargs ):
logger.info("CustomPlayer.__init__")
self.actualtime=0
self.totaltime=0
self.stopped=False
xbmc.Player.__init__( self )
def wait2second():
logger.info("tvalacarta.platformcode.xbmctools wait2second")
import time
contador = 0
while xbmc.Player().isPlayingVideo()==False:
logger.info("tvalacarta.platformcode.xbmctools setSubtitles: Waiting 2 seconds for video to start before setting subtitles")
time.sleep(2)
contador = contador + 1
if contador>10:
break
# TODO: Pasar esto a custom player
def setSubtitles():
logger.info("tvalacarta.platformcode.xbmctools setSubtitles")
import time
contador = 0
while xbmc.Player().isPlayingVideo()==False:
logger.info("tvalacarta.platformcode.xbmctools setSubtitles: Waiting 2 seconds for video to start before setting subtitles")
time.sleep(2)
contador = contador + 1
if contador>10:
break
subtitlefile = os.path.join( config.get_data_path(), 'subtitulo.srt' )
logger.info("tvalacarta.platformcode.xbmctools setting subtitle file %s" % subtitlefile)
xbmc.Player().setSubtitles(subtitlefile)
def playMedia(title, thumbnail, link, mediaType='Video') :
"""Plays a video
Arguments:
title: the title to be displayed
thumbnail: the thumnail to be used as an icon and thumbnail
link: the link to the media to be played
mediaType: the type of media to play, defaults to Video. Known values are Video, Pictures, Music and Programs
"""
li = xbmcgui.ListItem(label=title, iconImage=thumbnail, thumbnailImage=thumbnail, path=link)
li.setInfo(type=mediaType, infoLabels={ "Title": title })
xbmc.Player().play(item=link, listitem=li)
def playMedia(title, thumbnail, link, mediaType='Video') :
"""Plays a video
Arguments:
title: the title to be displayed
thumbnail: the thumnail to be used as an icon and thumbnail
link: the link to the media to be played
mediaType: the type of media to play, defaults to Video. Known values are Video, Pictures, Music and Programs
"""
li = xbmcgui.ListItem(label=title, iconImage=thumbnail, thumbnailImage=thumbnail, path=link)
li.setInfo(type=mediaType, infoLabels={ "Title": title })
xbmc.Player().play(item=link, listitem=li)
def playMedia(title, thumbnail, link, mediaType='Video') :
"""Plays a video
Arguments:
title: the title to be displayed
thumbnail: the thumnail to be used as an icon and thumbnail
link: the link to the media to be played
mediaType: the type of media to play, defaults to Video. Known values are Video, Pictures, Music and Programs
"""
li = xbmcgui.ListItem(label=title, iconImage=thumbnail, thumbnailImage=thumbnail, path=link)
li.setInfo(type=mediaType, infoLabels={ "Title": title })
xbmc.Player().play(item=link, listitem=li)
def playMedia(title, thumbnail, link, mediaType='Video') :
"""Plays a video
Arguments:
title: the title to be displayed
thumbnail: the thumnail to be used as an icon and thumbnail
link: the link to the media to be played
mediaType: the type of media to play, defaults to Video. Known values are Video, Pictures, Music and Programs
"""
li = xbmcgui.ListItem(label=title, iconImage=thumbnail, thumbnailImage=thumbnail, path=link)
li.setInfo(type=mediaType, infoLabels={ "Title": title })
xbmc.Player().play(item=link, listitem=li)
def onInit( self ):
xbmc.Player().play('%s/resources/skins/DefaultSkin/media/xbmchub.mp3'%ADDON.getAddonInfo('path'))# Music.
while self.shut > 0:
xbmc.sleep(1000)
self.shut -= 1
xbmc.Player().stop()
self._close_dialog()
def onClick( self, controlID ):
if controlID == 12:
xbmc.Player().stop()
self._close_dialog()
if controlID == 7:
xbmc.Player().stop()
self._close_dialog()
def onAction( self, action ):
if action in [ 5, 6, 7, 9, 10, 92, 117 ] or action.getButtonCode() in [ 275, 257, 261 ]:
xbmc.Player().stop()
self._close_dialog()
def PLAY_STREAM(name,url,iconimage):
dp = xbmcgui.DialogProgress()
r=' Please Wait While We Load [COLOR yellow][B]%s[/B][/COLOR]'%(name)
dp.create("NotFilmOn",'',r,'')
programme_id=str(iconimage).replace('http://static.filmon.com/couch/channels/','').replace('/big_logo.png','')
GA_track(programme_id,name)
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name} )
liz.setProperty("IsPlayable","true")
pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
pl.clear()
pl.add(url, liz)
xbmc.Player(xbmc.PLAYER_CORE_MPLAYER).play(pl)
dp.close()
def play(self, url, listitem):
print 'Now im playing... %s' % url
self.stopPlaying.clear()
xbmc.Player().play(url, listitem)