资 源 简 介
简单的基本功能,实测可行。 核心代码: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); } }}