xbmc.player() stalls right after I stop the video in android
#1
xbmc.player() stalls right after I stop the video and I end up with a frozen screen. Android Nvidia shield - Code works flawlessly on other platforms. I do not know how to start debugging it!
python:
    def _play_film(self, urlparam):
        "Play the stream corresponding to title."
        film = urlparam.split("=")[1]
        film = unquote(film) 

        with self.connect_films_db() as db_con:
            c = db_con.cursor()

            query = "SELECT player_link FROM films WHERE title = ?"
            c.execute(query, (film,))
            result = c.fetchone()

        if result is not None and len(result) > 0:
            player_link = result[0]
            scraper = Scraper2()
            film_page = scraper.get_film_page_in_a_string(player_link)

            films2 = Films2()
            mp4_url = films2.mp4_url_link(film_page)
            
            path = mp4_url[0]
            listitem = xbmcgui.ListItem(path=path)

            req = urllib.request.Request(path)
            req.add_header('User-Agent', USER_AGENT)

            with urllib.request.urlopen(req) as response:
                xbmc.Player().play(response.url)   
Reply
#2
for dynamic urls you should use setResolvedUrl method not Player
Reply
#3
(2023-07-21, 10:09)V8MEM Wrote: for dynamic urls you should use setResolvedUrl method not Player
Question: How do we determine a dynamic url, I am getting this url link from a source page and not from XHR?
Here is my new implementation of code is it correct?:
python:
import xbmcgui
import xbmcplugin

def _play_film(self, urlparam):
    "Play the stream corresponding to title."
    film = urlparam.split("=")[1]
    film = unquote(film) 

    with self.connect_films_db() as db_con:
        c = db_con.cursor()

        query = "SELECT player_link FROM films WHERE title = ?"
        c.execute(query, (film,))
        result = c.fetchone()

    if result is not None and len(result) > 0:
        player_link = result[0]
        scraper = Scraper2()
        film_page = scraper.get_film_page_in_a_string(player_link)

        films2 = Films2()
        mp4_url = films2.mp4_url_link(film_page)
        
        path = mp4_url[0]
        listitem = xbmcgui.ListItem(path=path)
        listitem.setResolvedUrl(isFolder=False, succeeded=True)
        xbmcplugin.setResolvedUrl(plugin.handle, True, listitem)
Reply
#4
Where can I find official documentation for 'setResolvedUrl' ? I found a lot of examples but do not find xbmc documentation for it
Reply
#5
reference - https://romanvm.github.io/Kodistubs/_aut...lugin.html

the last time i used it -

import xbmcplugin, xbmcgui
phandle = int(sys.argv[1])
xbmcplugin.setResolvedUrl(phandle, True, xbmcgui.ListItem(path='path/or/url/to/play.here'))
Reply
#6
(2023-07-21, 17:13)jepsizofye Wrote: reference - https://romanvm.github.io/Kodistubs/_aut...lugin.html

the last time i used it -

import xbmcplugin, xbmcgui
phandle = int(sys.argv[1])
xbmcplugin.setResolvedUrl(phandle, True, xbmcgui.ListItem(path='path/or/url/to/play.here'))
Thanks for your response... The following does not play the url at all. What am I doing wrong?
python:
    def _register_addon(self):
        "Register AddOn."
        self._plugin_id = int(sys.argv[1])
        
    def _play_film(self, urlparam):
        "Play the stream corresponding to title."
        film = urlparam.split("=")[1]
        film = urllib.parse.unquote(film)
    
        headers = {'User-Agent': USER_AGENT}  # Add the User-Agent header here
    
        with self.connect_films_db() as db_con:
            c = db_con.cursor()

            query = "SELECT player_link FROM films WHERE title = ?"
            c.execute(query, (film,))
            result = c.fetchone()

        if result is not None and len(result) > 0:
            player_link = result[0]
            scraper = Scraper2()
            film_page = scraper.get_film_page_in_a_string(player_link)

            films2 = Films2()
            mp4_url = films2.mp4_url_link(film_page)
        
            path = mp4_url[0]
            req = urllib.request.Request(path, headers=headers) 
            response = urllib.request.urlopen(req)
            listitem = xbmcgui.ListItem(path=response.geturl())
            xbmcplugin.setResolvedUrl(self._plugin_id, True, listitem) 
Reply
#7
its not clear how you are opening, the setresolvedurl method will tell kodi where to load something when an item is clicked in the ui

so, if you have a video addon, the video addon displays a bunch of listitems for each video item, when one of those listitems is clicked it connects to the addon, at that point the setresolvedurl can "redirect" the path kodi is trying to play to a different path or url

if you are simply trying to start playback from a script, where no gui or listitems are involved, you can simply use PlayMedia

from a script it can look like this - xbmc.executebuiltin('PlayMedia("path/or/url/to/play.here")')

you can also use jsonrpc https://gist.github.com/hamidzr/f0fda69a...0876ffc467
Reply
#8
(2023-07-21, 17:54)jepsizofye Wrote: its not clear how you are opening, the setresolvedurl method will tell kodi where to load something when an item is clicked in the ui

so, if you have a video addon, the video addon displays a bunch of listitems for each video item, when one of those listitems is clicked it connects to the addon, at that point the setresolvedurl can "redirect" the path kodi is trying to play to a different path or url

if you are simply trying to start playback from a script, where no gui or listitems are involved, you can simply use PlayMedia

from a script it can look like this - xbmc.executebuiltin('PlayMedia("path/or/url/to/play.here")')

you can also use jsonrpc https://gist.github.com/hamidzr/f0fda69a...0876ffc467

This is what I have:
1- I scrap the url for the list of available films and store them in a database (title, poster, player page)
2- Then i list items on the kodi screen to be clicked and then played
3- When I click in each image or item on the screen it goes to the database for that item to them extract the playable url link from the player page
(Meaning that I only have one playable url at a time and just when I click on the screen it goes to fetch it)
4- then I expect it to play it ... This how it is successfully working on Win and OSX... No in Android

** I used the code with 'xbmc.executebuiltin' and it does exactly the same! it freezes
***Actually it is worth to mention that I have another folder that plays live content in the same addon using the same code (the one initially posted above) and it works correctly without a problem in all platforms. Only difference is that it does not use a database. So I started thinking there is something else (may be database) that causes that freezing in Android. How can I debug it ? There are no errors in the log...
Reply
#9
might try to simplify

in your main py file that is defined in the addon.xml just execute the setresolvedurl with a static url and step through the code that way to see what part is freezing

kodi might be waiting for your code to return or exit and getting stuck in a loop which causes it to die on android where the other platforms simply "handle it"

would be curious if on the other platforms you have high cpu usage instead of a crash/freeze
Reply
#10
(2023-07-21, 21:24)jepsizofye Wrote: might try to simplify

in your main py file that is defined in the addon.xml just execute the setresolvedurl with a static url and step through the code that way to see what part is freezing

kodi might be waiting for your code to return or exit and getting stuck in a loop which causes it to die on android where the other platforms simply "handle it"

would be curious if on the other platforms you have high cpu usage instead of a crash/freeze
Thanks,
Yes there is high cpu usage!
Also, I still need to be able to play url using 'setResolvedUrl'. Like i said above this code does not play it.. and I need to do it before I try logging it as you suggest.

Code:
        if result is not None and len(result) > 0:
            player_link = result[0]
            scraper = Scraper2()
            film_page = scraper.get_film_page_in_a_string(player_link)

            films2 = Films2()
            mp4_url = films2.mp4_url_link(film_page)
        
            path = mp4_url[0]
            req = urllib.request.Request(path, headers=headers) 
            response = urllib.request.urlopen(req)
            listitem = xbmcgui.ListItem(path=response.geturl())
            xbmcplugin.setResolvedUrl(self._plugin_id, True, listitem) 
Reply
#11
(2023-07-21, 21:24)jepsizofye Wrote: kodi might be waiting for your code to return or exit and getting stuck in a loop which causes it to die on android where the other platforms simply "handle it"

Right on! I was not properly closing the database by having incorrect indentation! The 'if' clause was not inside the 'with' statement leaving database open thereafter causing high CPU usage and  freezing on Android.  Obviously the computer with more RAM was still able to handle it and play the video!
Reply
#12
(2023-07-21, 10:09)V8MEM Wrote: for dynamic urls you should use setResolvedUrl method not Player

After doing some reading I understand that, xbmcplugin.setResolvedUrl() sets the URL for a media item, but it does not trigger the actual playback. After setting the resolved URL using setResolvedUrl(), you would typically call xbmc.Player().play with the resolved URL to initiate the playback of the media.
So in conclusion, in order to play media, you would use xbmcplugin.setResolvedUrl() to provide the resolved URL to Kodi's player, and then use xbmc.Player().play to start the playback.
Please someone confirm if this is correct or I am still missing something?
Thanks
Reply
#13
No, that is not correct. There is no need for a plugin to interact with the player directly just to play a video.
Quote:This is what I have:
1- I scrap the url for the list of available films and store them in a database (title, poster, player page)
2- Then i list items on the kodi screen to be clicked and then played
Did you set the property IsPlayable on these items - list_item.setProperty('IsPlayable', 'true')?
This is required so Kodi knows it can expect a resolved url when the item is clicked and will start playing once setResolvedUrl() is called.
Reply
#14
(2023-07-24, 14:07)kereltje Wrote: This is required so Kodi knows it can expect a resolved url when the item is clicked and will start playing once setResolvedUrl() is called.

Thanks for your response. I added that line but did not make a difference... What am I missing? Would you mind posting your code version from the one I posted above? tks
Reply
#15
Quote:This is what I have:
1- I scrap the url for the list of available films and store them in a database (title, poster, player page)
2- Then i list items on the kodi screen to be clicked and then played
3- When I click in each image or item on the screen it goes to the database for that item to them extract the playable url link from the player page
(Meaning that I only have one playable url at a time and just when I click on the screen it goes to fetch it)
4- then I expect it to play it ... This how it is successfully working on Win and OSX... No in Android
As I understand the code you posted only concerns step 3.
In order "to be clicked and then played" ListItems produced in step 2 must be marked as playable by calling setProperty('IsPlayable', 'true') on each of them.
And remove everything regarding xbmc.Player() that might still be in step 3.
Reply

Logout Mark Read Team Forum Stats Members Help
xbmc.player() stalls right after I stop the video in android0