populate <control type="image"> and also <control type="videowindow"> using xbmcgui
#1
I have a python addon that uses xbmcgui to populate lists and when I have images inside a list, then I am able to populate them just fine using the following code:

in Python:

        list_item = xbmcgui.ListItem(label=filename)
        list_item.setArt({'image': item['image'], 'icon': item['image'], 'fanart': item['image']})
        # item['image'] holds url to image
        listitems.append(list_item) 
        myList.addItems(listitems)

and in the XML I am able to retrieve the url/path to image file as follows:
<!-- this is inside a list control -->
                <control type="image">
                    <top>5</top>
                    <left>5</left>
                    <width>150</width>
                    <height>150</height>
                    <info>ListItem.Icon</info>
                </control>

Can someone help me do the same without the Image control being inside a List control ? i.e. what control and properties will I set in xbmcgui if this image control was not inside a list?

Also, I need to do the same with a Video control as well. I could not find any examples on these. Thanks in advance.
Reply
#2
add an id to the image control, then use getControl() and setImage()

for the video control, just add one to your xml file. there's nothing else you need to do.
if you set 'windowed' to True in the play() command, the video will be played inside your video window.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
Thanks Ronie.

I ran into a different issue that had to be addressed before I could try the Video playback. I finally got that resolved an hour ago.

I tried your suggestions to play the Video, but it doesn't seem to work. Its been a long day, I'm going to try it again tomorrow and update here.
Reply
#4
Hi Ronie, I tried it with another URL for Video from internet that works in sample code. But it does not play in my code.

Here it is for your review, please advice.

-------------------   CustomVideo.XML   ---------------

<?xml version="1.0" encoding="UTF-8"?>
<window id="1139">
    <controls>
        <control type="panel" id="300">
            <left>0</left>
            <top>0</top>
            <width>1280</width>
            <height>720</height>
            <onleft>9000</onleft>
            <onright>60</onright>
            <onup>52</onup>
            <ondown>52</ondown>
            <scrolltime tween="sine" easing="out">200</scrolltime>
            <autoscroll>false</autoscroll>
            <viewtype label="3D list">list</viewtype>
            <pagecontrol>60</pagecontrol>
            <itemlayout height="1280" width="720">
                <control type="videowindow">
                    <top>0</top>
                    <left>0</left>
                    <width>1280</width>
                    <height>720</height>
                    <info>ListItem.Property("urlToMediaFile")</info>
                </control>
            </itemlayout>
            <focusedlayout height="1280" width="720">
                <control type="videowindow">
                    <top>0</top>
                    <left>0</left>
                    <width>1280</width>
                    <height>720</height>
                    <info>ListItem.Property("urlToMediaFile")</info>
                </control>
            </focusedlayout>            
        </control>
    </controls>
</window>

I have some other control in this XML as well, but to keep this short I've removed them.  

When the addon executes I see a blank screen, the video does not play.

-----------   Python addon:     -----------

# add a class to create your xml based window
class GUI(xbmcgui.WindowXML):

    def onInit(self):
        urlToVideo = 'http://www.vidsplay.com/wp-content/uploads/2017/05/traffic1.mp4'
        play_video(self, urlToVideo, 300)

# end of class

def play_video(self, urlToVideo, panelID):
    play_item = xbmcgui.ListItem(path=urlToVideo)
    curPanel = self.getControl(300)

    curPanel.addItem(play_item)
    # Pass the item to the Kodi player.
    xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)

if (__name__ == '__main__'):
    ui = GUI('CustomVideo.xml', CWD, 'default', '720p', testKey=sys.argv[2][1:])
    ui.doModal()
    del ui
Reply
#5
1. you can't use a videowindow control inside a container (list / panel). you need to place it outside of it.
only labels / images can be used in lists.

2. don't use any xbmcplugin code in your addon, you're creating script, not a plugin.

3. to play a video, you need to use the play() function i refered to in my previous reply.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#6
Thanks Ronie. I'll try that in a few minutes and report back.

The reason I tried list is because the link and the example you suggested has a listitem in it. What should I provide as an argument in lieu of listitem ?

Since my XML has different types of controls, like multiple images, labels but only one videowindow control, how should I tie this play command to that control ? 

---- from weblinks you've provided -----

 play([item, listitem, windowed, startpos]) 

Example:
....
listitem = xbmcgui.ListItem('Ironman')
listitem.setInfo('video', {'Title': 'Ironman', 'Genre': 'Science Fiction'})
xbmc.Player().play(url, listitem, windowed)
xbmc.Player().play(playlist, listitem, windowed, startpos)
Reply
#7
check the description of the params... where  [opt] means optional ;-)
a listitem is only needed if you want to set infolabels for the videoplayer, like VideoPlayer.Genre or VideoPlayer.Year

if you set the 'windowed' param to True, the video will be played back in your videowindow control.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#8
Thanks Ronie.

The video plays fine now. But when the Video ends it shows me terminal screen which has log messages regarding the Video playback (HDMI etc, same can be found under dmesg). I then have to press a key for my script to take back control and display the images that were displayed before the Video started playing.

Here is the sequence of events that happens on my script:

- When the script runs, it shows a panel with thumbnails of images and Videos.
- when I clicks on any of the thumbnails, it gets displayed on fullscreen.
- if the item is a video file, then a fullscreen thumbnail is displayed with a play button (image) in the center.
- if the user clicks OK/play then the play_video is called and it plays the video.
- but when the video ends, it takes us to a terminal like screen which has the logs that were generated to prepare and play the video.
- when I click on left or right or probably any other button, thats when the panel with fullscreen becomes active and visible on screen again.

I want when the video ends, it take us back to the screen where I had clicked OK to start the Video. I do not want the terminal like window showing logs to become visible at all. (if it matters I have already done sudo dmesg -D to disable console logging of dmesg)

Here is the play_video method that plays the video:

def play_video(urlToVideo):
    urlToVideo = 'http://www.vidsplay.com/wp-content/uploads/2017/05/traffic1.mp4'
    # the video I provide is not setup on the server side, so I am using this known video that works.

    play_item = xbmcgui.ListItem(path=urlToVideo)
    xbmc.Player().play(urlToVideo, play_item, True)
    the listitem is optional, but in order to specify windowed as True, I needed to provide something for lisitem.
Reply
#9
Ronie,
I did some more testing and troubleshooting and here is what I see:

- Regardless of windowed or fullscreen mode. The video plays fine. However when it reaches the end of video ( 2 min or 2 hour video doesn't matter), I see error messages generated in log and my script seems to reload. (I see onInit event being called) 

06:44:47.733 T:545571737792  NOTICE: CVideoPlayer::OnExit()
06:44:47.734 T:545571737792  NOTICE: VideoPlayer: eof, waiting for queues to empty
06:44:47.734 T:545571737792  NOTICE: Closing stream player 1
06:44:47.734 T:545571737792  NOTICE: CDVDMessageQueue(audio)::WaitUntilEmpty
06:44:47.748 T:545571737792  NOTICE: Waiting for audio thread to exit
06:44:47.749 T:545393733824  NOTICE: thread end: CVideoPlayerAudio::OnExit()
06:44:47.749 T:545571737792  NOTICE: Closing audio device
06:44:48.176 T:545571737792  NOTICE: Deleting audio codec
06:44:48.177 T:545571737792  NOTICE: Closing stream player 2
06:44:48.177 T:545571737792  NOTICE: CDVDMessageQueue(video)::WaitUntilEmpty
06:44:48.202 T:545571737792  NOTICE: waiting for video thread to exit
06:44:48.202 T:545551270080   ERROR: Got MSGQ_ABORT or MSGO_IS_ERROR return true
06:44:48.202 T:545551270080  NOTICE: thread end: video_thread
06:44:48.203 T:545571737792  NOTICE: deleting video codec
06:44:48.290 T:545571737792  NOTICE: Closing stream player 3
06:44:48.351 T:546912071872  NOTICE: mainWithgui.py: Entered onInit(self)

Any advice on the Error handling here ? 

other issues:
- when I play a 4k Video, then before the video starts playing, for a split second I see shell with log messages, then it starts playing video.
- same thing happens when the video ends, I see shell for a split second and then my script loads again.

Any advice on how to make the shell NOT appear at all ?

Thanks,

P.S. - - If I stream video from a website, will the play method download/cache the entire file or can it simply buffer some and play as we go along ? I would prefer it buffer a small part and not try to cache the entire file because some of my videos could be several gigabyte in size.
Reply
#10
(2018-01-24, 04:39)ajiratech Wrote:     play_item = xbmcgui.ListItem(path=urlToVideo)
    xbmc.Player().play(urlToVideo, play_item, True)
    the listitem is optional, but in order to specify windowed as True, I needed to provide something for lisitem.
 not really, you can just use keywords:
python:
xbmc.Player().play(urlToVideo, windowed=True)

i have no idea about the terminal screen issue.. but it sound like kodi minimizes when the video ends?
don't have a clue about the error in the log either.

as for caching, as far as i know that's all being handled by kodi and not something you have to worry about in your addon.
you can tweak the cache settings for your system using advancedsettings.xml
http://kodi.wiki/view/HOW-TO:Modify_the_cache
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#11
Thanks Ronie.

I'll try it with keywords:
Code:
xbmc.Player().play(urlToVideo, windowed=True)

As for terminal, I don't think Kodi gets minimized because I don't see it maximizing. It does however look like that Kodi disappears for a moment and makes the shell screen underneath Visible. Any suggestions on how to prevent that from happening ?

One more question regarding Video playback - I'm aware that Kodi has Settings -> Player -> MPEG2, MPEG4 and H.264 hardware acceleration options.

Is it instead possible to set acceleration on or off on a per file basis while we call the xbmc,player().play() ?  The reason I ask is because GPU acceleration fails for a lot of my Video files, If I can be selective on which files should use GPU acceleration then I do things like use GPU acceleration for 4K files only or if the video has certain info available, etc. 

Thanks!
Reply

Logout Mark Read Team Forum Stats Members Help
populate <control type="image"> and also <control type="videowindow"> using xbmcgui0