Python for android: mediaPlay (url) is useless. What should I do?

Source: Internet
Author: User

 

You can write it in this way.

Play. py

 

# -*- coding: utf-8 -*-import androidimport osdroid = android.Android()path = u'/sdcard/sl4a/test.mp3'url = u'file://' + pathif os.path.exists(path):    droid.startActivity('android.intent.action.VIEW',url,'audio/mp3')else:    print path,'not exists'

A practical example of mplay. py in the reference book

 

import androidimport os, sysdroid = android.Android()# Specify our root directory and make sure it exists.base_dir = '/sdcard/sl4a'if not os.path.isdir(base_dir):    print base_dir,'is not dir'    sys.exit(4)def show_dir(path=base_dir):    Shows the contents of a directory in a list view.    # The files & directories under path.    nodes = os.listdir(path)    # Make a way to go up a level.    if path != base_dir: nodes.insert(0, '..')    droid.dialogCreateAlert(os.path.basename(path).title())    droid.dialogSetItems(nodes)    droid.dialogShow()    # Get the selected file or directory.    result = droid.dialogGetResponse().result    droid.dialogDismiss()    if 'item' not in result:        return    target = nodes[result['item']]    target_path = os.path.join(path, target)    if target == '..': target_path = os.path.dirname(path)    # If a directory, show its contents.    if os.path.isdir(target_path):        show_dir(target_path)    elif os.path.splitext(target)[1].lower() == '.mp3':        url = 'file://' + target_path        print url        droid.startActivity('android.intent.action.VIEW',url, 'audio/mp3')    # inform the user.    else:        droid.makeToast('Only .mp3 files are currently supported!')        show_dir(path)if __name__ == '__main__':    show_dir()

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.