Android development Local and network MP3 Music Player (19) Notify Media Library to update newly downloaded MP3

Source: Internet
Author: User

Implementation features:

Notify Media Library Updates


Tangled up a few days, Baidu to a method that can be updated in Android 4.4, notify Media Library.

The Media Library is updated and the app is reopened to see the new songs, but this is still not perfect.

After the post will be implemented, the download music will be successful after you update the Media Library, update the local music list.

Because, there is no own server, so the network music all related functions (including search music, download music, download lyrics) can not guarantee the timeliness, suggestions, as soon as possible to download and practice; If you download, already because I collected the server change rule, please give me a message, if can solve, I will present a new source when I am free.

Until the current source download:
http://download.csdn.net/album/detail/3105
(Latest, please download the last one, this post corresponds to version 2.3; If you need to step through the process, please download all)

Welcome to Mobile development enthusiasts Exchange: mine is Iwanghang

In addition, I intend to start looking for a job, if Shenyang or the surrounding city company is interested, please contact me.

Achieve results


The implementation code is as follows:
Downloaddialogfragment as follows:
Package Com.iwanghang.drmplayer;import Android.app.alertdialog;import Android.app.dialog;import Android.content.broadcastreceiver;import Android.content.intent;import Android.content.intentfilter;import Android.database.cursor;import Android.graphics.path;import Android.media.mediascannerconnection;import Android.net.uri;import Android.os.environment;import Android.provider.mediastore;import Android.support.v4.app.dialogfragment;import Android.content.context;import Android.content.DialogInterface; Import Android.os.bundle;import android.util.log;import Android.view.view;import Android.widget.toast;import Com.iwanghang.drmplayer.utils.constant;import Com.iwanghang.drmplayer.utils.downloadutils;import Com.iwanghang.drmplayer.utils.mediascanner;import Com.iwanghang.drmplayer.utils.mediautils;import Com.iwanghang.drmplayer.utils.searchmusicutils;import Com.iwanghang.drmplayer.vo.searchresult;import Java.io.file;import java.io.ioexception;import java.util.arraylist;/** * Created by IwanghanG on 16/5/3. * Downloaddialogfargment */public class Downloaddialogfragment extends Dialogfragment {private SearchResult SearchResu    lt;//the current Song object to download private mainactivity mainactivity; public static downloaddialogfragment newinstance (SearchResult searchresult) {downloaddialogfragment DownloadDialogF        Ragment = new Downloaddialogfragment ();        Downloaddialogfragment.searchresult = SearchResult;    return downloaddialogfragment;    } private string[] items;        @Override public void Onattach (context context) {Super.onattach (context);        Mainactivity = (mainactivity) getactivity ();        Items = new string[]{"Download", "Cancel"};    Items = new String[]{getstring (r.string.download), getString (R.string.cancel)}; }//Create event Method for dialog @Override public Dialog oncreatedialog (Bundle savedinstancestate) {final Alertdialog.build        Er builder = new Alertdialog.builder (mainactivity); Builder.setcancelable (TRUE);//Return key to cancel Builder.setitems (iteMs,new Dialoginterface.onclicklistener () {@Override public void OnClick (dialoginterface dialog, int which) {switch (which) {case 0://execute Download D                        Ownloadmusic ();                    Break                        Case 1://Cancel Dialog.dismiss ();                Break        }            }        });    return Builder.show (); }//download music private void Downloadmusic () {Toast.maketext (mainactivity, "Downloading:" + searchresult.getmusicname (), T Oast.        Length_long). Show (); Downloadutils.getsinstance (). Setlistener (New Downloadutils.ondownloadlistener () {@Override public V                OID Ondowload (String mp3url) {//download succeeded Toast.maketext (mainactivity, "Download succeeded", Toast.length_short). Show (); System.out.println ("Downloaddialogfragment.downloadmusic @ =" + environment.getexternalstoragedirectory () +Con Stant. Dir_musiC + "/" + Mp3url);                 Update Media Library Scanfile (mainactivity,environment.getexternalstoragedirectory () +constant.dir_music + "/" + MP3URL);                Update local music list} @Override public void onfailed (String error) {//download failed            Toast.maketext (mainactivity, Error, Toast.length_short). Show ();    }}). Download (SearchResult); }//Update Media Library/** * Notify Media Library update file * @param context * @param filePath file Full path * * */public void Scanfil        E (Context context, String FilePath) {Intent scanintent = new Intent (intent.action_media_scanner_scan_file);        Scanintent.setdata (Uri.fromfile (New File (FilePath)));    Context.sendbroadcast (scanintent); }}


Android development Local and network MP3 Music Player (19) Notify Media Library to update newly downloaded MP3

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.