Hello, I think I have a really _really_ simple example that should
work like you wanted.
It may have some useless code (from copy-pasting other code)
2009/2/3 Olivier Tilloy <[email protected]>:
> Kristian Lippert a écrit :
>> Olivier wrote
>>> I had a very quick look at the code you sent me. I would say that it can
>>> be done in a much simpler way. If you already have the URLs to the MMS
>>> streams then you don't need a resource provider and new models. A simple
>>> controller that lists the streams and passes a PlayableModel to the
>>> player should do (in a first step, let's make things simple first, and
>>> then enrich them!). The player, being gstreamer-based, is perfectly able
>>> to handle MMS streams.
>>>
>>
>> Any examples in Elisa on the simple controller? (I know nothing of
>> Python and Elisa, but am an excellent C++ programmer). It is much easier
>> to learn by example for me!
>
> The YoutubeController (in
> elisa-plugins/elisa/plugins/youtube/controller.py) is pretty simple and
> you could base your controller on this. Your list of streams should be
> populated in the initialize() method.
> The rendering of the list items is implemented in the YoutubeViewMode
> that inherits from the GenericListViewMode.
>
> API documentation is available at
> http://elisa.fluendo.com/documentation/api/elisa.plugins.poblesec.base.hierarchy.HierarchyController.html
> and
> http://elisa.fluendo.com/documentation/api/elisa.plugins.poblesec.base.list.GenericListViewMode.html.
>
> One gotcha you'll want to understand when working with Elisa: we make
> heavy use of twisted's deferreds mechanism to ensure a reactive UI at
> all moments. If you are not familiar with asynchronous programming and
> deferreds in particular, I advise you to start by reading the tutorial:
> http://twistedmatrix.com/projects/core/documentation/howto/deferredindepth.html.
>
>> Best Regards,
>> Kristian
>
> Cheers,
>
> Olivier
>
# -*- coding: utf-8 -*-
# vim: expandtab:tabstop=4
from elisa.core.utils import defer
from elisa.plugins.poblesec.link import Link
from elisa.core.media_uri import MediaUri
from elisa.plugins.poblesec.base.hierarchy import HierarchyController
from elisa.plugins.poblesec.base.list import GenericListViewMode
from elisa.plugins.poblesec.base.preview_list import MenuItemPreviewListController
from elisa.plugins.poblesec.base.coverflow import ImageWithReflectionCoverflowController
from elisa.plugins.poblesec.base.grid import GridItemGridController
from elisa.plugins.poblesec.base.list_switcher import ListSwitcherController
from elisa.plugins.base.models.media import PlayableModel
def myradio_decorator(controller):
link = Link()
link.controller_path = '/poblesec/myradio'
link.label = 'My Radio'
link.icon = 'elisa.plugins.poblesec.radio'
controller.model.append(link)
return defer.succeed(None)
class MyRadioController(HierarchyController):
def initialize(self, uri=None):
dfr = super(MyRadioController, self).initialize()
def load_radio_list(self):
feeds = [('Best Rock FM', 'mms://195.23.102.196/bestrockcbr96'),
('M80 Radio', 'mms://195.23.102.196/m80cbr96'),
]
feed_models = []
for feed in feeds:
feed_model = PlayableModel()
feed_model.title = feed[0]
feed_model.uri = MediaUri(feed[1])
feed_models.append(feed_model)
self.model.extend(feed_models)
return self
if uri is None:
dfr.addCallback(load_radio_list)
return dfr
def node_clicked(self, widget, model):
if isinstance(model, PlayableModel):
player = self.frontend.retrieve_controllers('/poblesec/music_player')[0].player
player.play_model(model)
main = self.frontend.retrieve_controllers('/poblesec')[0]
main.show_music_player()
self.stop_loading_animation()
class MyRadioViewMode(GenericListViewMode):
"""
Implementation of the common view modes API.
"""
def get_label(self, item):
return defer.succeed(item.title)
def get_default_image(self, item):
resource = 'elisa.plugins.poblesec.file'
if isinstance(item, PlayableModel):
resource = 'elisa.plugins.poblesec.radio'
return resource
def get_image(self, item, theme):
return None
def get_preview_image(self, item, theme):
return None
class MyRadioPreviewListController(MyRadioController, MenuItemPreviewListController):
view_mode = MyRadioViewMode
class MyRadioCoverflowController(MyRadioController, ImageWithReflectionCoverflowController):
view_mode = MyRadioViewMode
class MyRadioGridController(MyRadioController, GridItemGridController):
view_mode = MyRadioViewMode
class MyRadioListSwitcherController(ListSwitcherController):
modes = [MyRadioPreviewListController,
MyRadioCoverflowController,
MyRadioGridController]
default_mode = MyRadioPreviewListController
# -*- coding: utf-8 -*-
import os
from setuptools import setup
from elisa.core.utils.dist import find_packages, TrialTest, Clean
packages, package_dir = find_packages(os.path.dirname(__file__))
cmdclass = dict(test=TrialTest, clean=Clean)
setup(name='elisa-plugin-myradio',
version='0.0.1',
description='my radio',
license='GPL3',
author='João Rodrigues',
author_email='[email protected]',
namespace_packages=['elisa', 'elisa.plugins'],
packages=packages,
package_dir=package_dir,
controller_mappings=[('/poblesec/myradio',
'elisa.plugins.myradio.controller:MyRadioListSwitcherController'),
],
decorator_mappings=[('/poblesec/music/internet',
'elisa.plugins.myradio.controller:myradio_decorator'),
],
cmdclass=cmdclass)