登录
首页 » Java » android 播放网络MP3 音乐播放

android 播放网络MP3 音乐播放

于 2014-05-26 发布
0 94
下载积分: 1 下载次数: 0

代码说明:

简单的基本功能,实测可行。 核心代码:package com.sharpandroid.music.activity;import java.io.IOException;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.ImageButton;import android.widget.SeekBar;import android.widget.TextView;import com.sharpandroid.music.R;import com.sharpandroid.music.StreamingMediaPlayer;public class MediaPlayer extends Activity { private Button streamButton; private ImageButton playButton; private boolean isPlaying; private TextView playTime; private StreamingMediaPlayer audioStreamer; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); initControls(); } private void initControls() { playTime=(TextView) findViewById(R.id.playTime); streamButton = (Button) findViewById(R.id.button_stream); streamButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { startStreamingAudio(); }}); playButton = (ImageButton) findViewById(R.id.button_play); playButton.setEnabled(false); playButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (audioStreamer.getMediaPlayer().isPlaying()) { audioStreamer.getMediaPlayer().pause(); playButton.setImageResource(R.drawable.button_play); } else { audioStreamer.getMediaPlayer().start(); audioStreamer.startPlayProgressUpdater(); playButton.setImageResource(R.drawable.button_pause); } isPlaying = !isPlaying; }}); } private void startStreamingAudio() { try { final SeekBar progressBar = (SeekBar) findViewById(R.id.progress_bar); if ( audioStreamer != null) { audioStreamer.interrupt(); } audioStreamer = new StreamingMediaPlayer(this, playButton, streamButton, progressBar,playTime); audioStreamer.startStreaming("http://192.168.64.1/xa.mp3",5208, 216); streamButton.setEnabled(false); } catch (IOException e) { Log.e(getClass().getName(), "读取音乐出错!", e); } }}

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 696518资源总数
  • 104269会员总数
  • 31今日下载