Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中保存应用程序中的歌曲?_Android_Android Intent_Android Activity - Fatal编程技术网

如何在android中保存应用程序中的歌曲?

如何在android中保存应用程序中的歌曲?,android,android-intent,android-activity,Android,Android Intent,Android Activity,我无法从互联网上下载歌曲,但我可以收听歌曲,但我希望我的应用程序能够执行,当我单击播放按钮时,它也应该下载该歌曲 playbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub mPlayer = new MediaPlayer();

我无法从互联网上下载歌曲,但我可以收听歌曲,但我希望我的应用程序能够执行,当我单击播放按钮时,它也应该下载该歌曲

playbtn.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
         mPlayer = new MediaPlayer();
        if(web[position] == web[0]){

        if(mPlayer.isPlaying()){
            mPlayer.stop();
            mPlayer.prepareAsync();
            mPlayer.seekTo(0);

        }      
        else{   
            Uri myUri1 = Uri.parse("http://sound21.mp3slash.net/320/indian/bajrangibhaijaan/01%20-%20Selfie%20Le%20Le%20Re%20-%20Bajrangi%20Bhaijaan%20[Songspk.LINK].mp3");

        try {
            mPlayer.setDataSource(getContext(), myUri1);
        } catch (IllegalArgumentException e) {
            Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (SecurityException e) {
            Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IllegalStateException e) {
            Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            mPlayer.prepare();
        } catch (IllegalStateException e) {
           Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        }
        mPlayer.start();
        playbtn.setText("Pause");
    }   

你的意思是当你点击按钮,开始播放和下载? 使用DownloadManager下载音频文件。

那么,有什么错误吗?检查这个@JagadeshSeeram先生,我如何使用它我必须创建一个单独的类,然后如何将它用于每首不同的歌曲。是的,但我可以获得它如何使用下载管理器我使用了它,但它不起作用。