[Player-dev] Re: [Midplayer-private-dev] CR: Fix utils::get_media_type() implementation
Rusty Lynch rusty.lynch at intel.comChecked into HEAD
On Wed, 2008-03-19 at 19:22 -0700, Rusty Lynch wrote:
> Description
> ----------------------------------
> When the MID player plays a given media file, it needs to guess if the
> media file is video, photo, or music in order to present the correct UI.
> The current implementation does this by using the file extention, which
> is problematic for many extensions (like 'rm' or 'ogg'.)
>
> Before this change, the utility function for determining the media type
> would just do a simple iteration over a list of known extension types,
> ensuring that there is always a combination of getting this wrong.
>
> This changeset will add a small amount of smarts to the get_media_type()
> function to pick the media type that makes sense for the given view. A
> classic example is if the music view attempts to play a rm file, then it
> will be played as music, and if the same file was played from the video
> view
> then it will be played as video.
>
> Files Modified
> ----------------------------------
> player/mid/src/toolbar_view.py
> player/mid/src/utils.py
>
> Branches
> ---------------------------------
> HEAD only (for now)
>
> Index: src/toolbar_view.py
> ===================================================================
> RCS file: /cvsroot/player/mid/src/toolbar_view.py,v
> retrieving revision 1.2
> diff -u -w -r1.2 toolbar_view.py
> --- src/toolbar_view.py 18 Mar 2008 00:04:02 -0000 1.2
> +++ src/toolbar_view.py 20 Mar 2008 02:18:11 -0000
> @@ -474,7 +474,7 @@
> filename = PlayList(filename)[0]['File']
> except PlayListError:
> return utils.error_msg(constant.MSG_OPEN_ERROR, False)
> - media_type = utils.get_media_type(filename)
> + media_type = utils.get_media_type(filename, self.app.cur_mode)
> dirname = filename.replace('file://','')
> self.app.view['photo'].set_cur_dir(dirname)
> if -1 == filename.find(":"):
> Index: src/utils.py
> ===================================================================
> RCS file: /cvsroot/player/mid/src/utils.py,v
> retrieving revision 1.3
> diff -u -w -r1.3 utils.py
> --- src/utils.py 18 Mar 2008 00:04:02 -0000 1.3
> +++ src/utils.py 20 Mar 2008 02:18:11 -0000
> @@ -88,18 +88,22 @@
> parser.error("no such media mode, only support music, video
> and photo")
> return options, args
>
> -def get_media_type(filename):
> - """Based on the extension of the filename, determine what the media
> type
> - is"""
> +def get_media_type(filename, calling_view = 'video'):
> + """Determine the media type by the file extension. For the case of
> + file extensions that resolve to multiple media types (like
> 'rm'), then
> + give preference to the the calling view (i.e. if the music view
> + is asking then rm is 'audio', but if the video view is asking
> then
> + the media type is 'video'"""
> strlist = filename.split('.')
> extension = strlist[-1].lower()
> - if extension in constant.MediaType['audio']:
> - return 'audio'
> - elif extension in constant.MediaType['video']:
> - return 'video'
> - elif extension in constant.MediaType['photo']:
> - return 'photo'
> - else:
> + for i in [calling_view, 'audio', 'photo', 'video']:
> + try:
> + if extension in constant.MediaType[i]:
> + return i
> + except:
> + # Somebody passed in an invalid calling view
> + pass
> + # If all else fails then default to audio
> return 'audio'
>
> def on_err_dialog_response_exit(dialog, response_id):
>
>
> _______________________________________________
> Midplayer-private-dev mailing list
> Midplayer-private-dev at lists.helixcommunity.org
> http://lists.helixcommunity.org/mailman/listinfo/midplayer-private-dev