当前位置:操作系统 > 安卓/Android >>

android易做图音乐

种方法是调用android自带的播放器


1 //调用系统自带播放器 

2         Intent intent = new Intent(); 

3         Uri uri = Uri.parse("http://mul1.tximg.cn/music/group/bbs/mp3/44/100715/1279159638887.mp3?z=909255638"); 

4         intent.setDataAndType(uri, "audio/*"); 

5         intent.setAction(Intent.ACTION_VIEW); 

6         startActivity(intent);


另一种方法是边下载边播放

这只是一种思路,参考别人的代码,实现分段下载,但是我的代码还很不完善,这方面不准备继续下去了。

 

01 package com.sharpandroid.music.activity; 

02   

03 import java.io.IOException; 

04 import android.app.Activity; 

05 import android.content.Intent; 

06 import android.net.Uri; 

07 import android.os.Bundle; 

08 import android.util.Log; 

09 import android.view.View; 

10 import android.widget.Button; 

11 import android.widget.ImageButton; 

12 import android.widget.SeekBar; 

13 import android.widget.TextView; 

14   

15 import com.sharpandroid.music.R; 

16 import com.sharpandroid.music.StreamingMediaPlay2; 

17 import com.sharpandroid.music.StreamingMediaPlayer; 

18   

19   

20 public class MediaPlayer extends Activity { 

21   

22     private Button streamButton; 

23     private ImageButton playButton; 

24     private boolean isPlaying; 

25     private TextView playTime; 

26     private StreamingMediaPlayer audioStreamer; 

27     private StreamingMediaPlay2 audioStreamer2; 

28       

29     @Override

30     public void onCreate(Bundle icicle) { 

31           

32         super.onCreate(icicle); 

33   

34         setContentView(R.layout.main); 

35         initControls(); 

36     }  

37       

38     private void initControls() { 

39         playTime=(TextView) findViewById(R.id.playTime); 

40         streamButton = (Button) findViewById(R.id.button_stream); 

41           

42         streamButton.setOnClickListener(new View.OnClickListener() { 

43             public void onClick(View view) { 

44                 startStreamingAudio(); 

45         }}); 

46   

47         playButton = (ImageButton) findViewById(R.id.button_play); 

48         playButton.setEnabled(false); 

49         playButton.setOnClickListener(new View.OnClickListener() { 

50             public void onClick(View view) { 

51                 if (audioStreamer2.getMediaPlayer().isPlaying()) { 

52                     audioStreamer2.getMediaPlayer().pause(); 

53                     playButton.setImageResource(R.drawable.button_play); 

54                 } else { 

55                     audioStreamer2.getMediaPlayer().start(); 

56                     //audioStreamer.startPlayProgressUpdater(); 

57                     playButton.setImageResource(R.drawable.button_pause); 

58                 } 

59                 isPlaying = !isPlaying; 

60         }}); 

61     } 

62       

63     private void startStreamingAudio() { 

64         final SeekBar progressBar = (SeekBar) findViewById(R.id.progress_bar); 

65         if ( audioStreamer != null) { 

66             audioStreamer.interrupt(); 

67         } 

68         //调用系统自带播放器 

69 //      Intent intent = new Intent(); 

70 //      Uri uri = Uri.parse("http://mul1.tximg.cn/music/group/bbs/mp3/44/100715/1279159638887.mp3?z=909255638"); 

71 //      intent.setDataAndType(uri, "audio/*"); 

72 //      intent.setAction(Intent.ACTION_VIEW); 

73 //      startActivity(intent); 

74             audioStreamer2 = new StreamingMediaPlay2(this, playButton, streamButton,  progressBar, playTime); 

75             audioStreamer2.startStreaming("http://mul1.tximg.cn/music/group/bbs/mp3/44/100715/1279159638887.mp3?z=909255638",5208, 216); 

76             streamButton.setEnabled(false); 

77                   

78     } 

79 }

 

 下一个文件


001 package com.sharpandroid.music; 

002   

003 import java.io.File; 

004 import java.io.FileInputStream; 

005 import java.io.FileOutputStream; 

006 import java.io.IOException; 

007 import java.io.InputStream; 

008 import java.net.MalformedURLException; 

009 import java.net.URL; 

010 import java.n

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,