I have a URL service, which has a MetadataObjectForURL function. This naturally uses the passed url to fetch metadata for the video in question, and one of these datafields that are fetched is the m3u8 url. I tried attaching a mediaobject with the metadataobject before returning it, like in the following snippet:
meta_object.add( MediaObject( video_resolution = 720, optimized_for_streaming = True, audio_channels = 2, parts = [ PartObject( key = HTTPLiveStreamURL(media_json['mediaUrl']) ) ] ) )
Unfortunately, this doesn't consistently work. It works with (perhaps incidentally) the live streams, but for the other streams – with the exact same container and codecs – the plugin halts/crashes with complaints in the log about missing associated MediaObjectsForURL functions.
Now, I've seen it said several places that MediaObjectsForURL functions should execute quickly and not perform any HTTP requests because of the delay in playing that the user might experience. But to get the m3u8 url in this function, I would need to do another lookup to the same url as in MetadataObjectForURL. I could pass it as an argument to a PlayVideo and add that as a callback, but then PlayVideo would have to do the lookup, which – if I understand the flow correctly – would cause the same delay for the user.
So the questions are: Why is it not consistently working the way I tried above? And if I have to make a MediaObjectsForURL function, how do I avoid doing several lookups to the same url, causing unnecessary delays? I'm sure there must be a best practice to this, and a way to avoid repeatedly doing the same request.