- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在努力播放 shoutcast 链接 (.pls) 我在 mp3 上成功了,我开始知道 shoutcast 链接在 android 中不起作用。有没有可能在 android http://stream.radiosai.net:8020/ 中播放此链接?
private final static String RADIO_STATION_URL = "http://stream.radiosai.net:8002/";
private ProgressBar playSeekBar;
private Button buttonPlay;
private Button buttonStopPlay;
private Button buttonRecord;
private Button buttonStopRecord;
private MediaPlayer player;
private InputStream recordingStream;
private RecorderThread recorderThread;
private boolean isRecording = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initializeUIElements();
initializeMediaPlayer();
}
private void initializeUIElements() {
playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);
playSeekBar.setMax(100);
playSeekBar.setVisibility(View.INVISIBLE);
buttonPlay = (Button) findViewById(R.id.buttonPlay);
buttonPlay.setOnClickListener(this);
buttonStopPlay = (Button) findViewById(R.id.buttonStopPlay);
buttonStopPlay.setEnabled(false);
buttonStopPlay.setOnClickListener(this);
buttonRecord = (Button) findViewById(R.id.buttonRecord);
buttonRecord.setOnClickListener(this);
buttonStopRecord = (Button) findViewById(R.id.buttonStopRecord);
buttonStopRecord.setOnClickListener(this);
}
public void onClick(View v) {
if (v == buttonPlay) {
startPlaying();
} else if (v == buttonStopPlay) {
stopPlaying();
} else if (v == buttonRecord) {
recorderThread = new RecorderThread();
recorderThread.start();
buttonRecord.setEnabled(false);
buttonStopRecord.setEnabled(true);
} else if (v == buttonStopRecord) {
stopRecording();
}
}
private void startPlaying() {
buttonStopPlay.setEnabled(true);
buttonPlay.setEnabled(false);
playSeekBar.setVisibility(View.VISIBLE);
player.prepareAsync();
player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
player.start();
player.pause();
buttonRecord.setEnabled(true);
}
});
}
private void stopPlaying() {
if (player.isPlaying()) {
player.stop();
player.release();
initializeMediaPlayer();
}
buttonPlay.setEnabled(true);
buttonStopPlay.setEnabled(false);
playSeekBar.setVisibility(View.INVISIBLE);
buttonRecord.setEnabled(false);
buttonStopRecord.setEnabled(false);
stopRecording();
}
private void initializeMediaPlayer() {
player = new MediaPlayer();
try {
player.reset();
player.setDataSource(RADIO_STATION_URL);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
playSeekBar.setSecondaryProgress(percent);
Log.i("Buffering", "" + percent);
}
});
}
@Override
protected void onPause() {
super.onPause();
if (player.isPlaying()) {
player.stop();
}
}
private void startRecording() {
BufferedOutputStream writer = null;
try {
URL url = new URL(RADIO_STATION_URL);
URLConnection connection = url.openConnection();
final String FOLDER_PATH = Environment
.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + "Songs";
File folder = new File(FOLDER_PATH);
if (!folder.exists()) {
folder.mkdir();
}
writer = new BufferedOutputStream(new FileOutputStream(new File(
FOLDER_PATH + File.separator + "listen.pls")));
recordingStream = connection.getInputStream();
final int BUFFER_SIZE = 100;
byte[] buffer = new byte[BUFFER_SIZE];
while (recordingStream.read(buffer, 0, BUFFER_SIZE) != -1
&& isRecording) {
writer.write(buffer, 0, BUFFER_SIZE);
writer.flush();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
recordingStream.close();
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void stopRecording() {
buttonStopRecord.setEnabled(false);
buttonRecord.setEnabled(true);
try {
isRecording = false;
if (recordingStream != null) {
recordingStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
private class RecorderThread extends Thread {
@Override
public void run() {
isRecording = true;
startRecording();
}
};
}
最佳答案
试试这个代码,detail is here :
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class SimpleMusicStream extends Activity implements
MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener,
MediaPlayer.OnErrorListener, MediaPlayer.OnBufferingUpdateListener {
private String TAG = getClass().getSimpleName();
private MediaPlayer mp = null;
private Button play;
private Button pause;
private Button stop;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
play = (Button) findViewById(R.id.play);
pause = (Button) findViewById(R.id.pause);
stop = (Button) findViewById(R.id.stop);
play.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
play();
}
});
pause.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
pause();
}
});
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
stop();
}
});
}
private void play() {
Uri myUri = Uri.parse("http://stream.radiosai.net:8002/");
try {
if (mp == null) {
this.mp = new MediaPlayer();
} else {
mp.stop();
mp.reset();
}
mp.setDataSource(this, myUri); // Go to Initialized state
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(this);
mp.setOnBufferingUpdateListener(this);
mp.setOnErrorListener(this);
mp.prepareAsync();
Log.d(TAG, "LoadClip Done");
} catch (Throwable t) {
Log.d(TAG, t.toString());
}
}
@Override
public void onPrepared(MediaPlayer mp) {
Log.d(TAG, "Stream is prepared");
mp.start();
}
private void pause() {
mp.pause();
}
private void stop() {
mp.stop();
}
@Override
public void onDestroy() {
super.onDestroy();
stop();
}
public void onCompletion(MediaPlayer mp) {
stop();
}
public boolean onError(MediaPlayer mp, int what, int extra) {
StringBuilder sb = new StringBuilder();
sb.append("Media Player Error: ");
switch (what) {
case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
sb.append("Not Valid for Progressive Playback");
break;
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
sb.append("Server Died");
break;
case MediaPlayer.MEDIA_ERROR_UNKNOWN:
sb.append("Unknown");
break;
default:
sb.append(" Non standard (");
sb.append(what);
sb.append(")");
}
sb.append(" (" + what + ") ");
sb.append(extra);
Log.e(TAG, sb.toString());
return true;
}
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.d(TAG, "PlayerService onBufferingUpdate : " + percent + "%");
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="Play"
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button
android:text="Pause"
android:id="@+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button
android:text="Stop"
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
关于android - 如何在 android 2.2 中播放 shoutcast 流媒体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8294989/
我正在使用 Twitter4j 流 API。我正在使用地理定位约束来仅从特定区域获取推文。这是代码的那部分: twitterStream.addListener(listener);
我正在使用 WCF 并希望将大文件从客户端上传到服务器。我已经调查并决定遵循 http://msdn.microsoft.com/en-us/library/aa717050.aspx 中概述的分块方
我和提问者的情况很相似: Can I serve MP3 files with PHP?基本上我试图保护 mp3 文件不被直接下载,因此用户必须首先通过 php 进行身份验证。这是我的代码: head
我连接了 Red5 oflaDemo 并且工作正常 当我尝试使用 ffmpeg rtmp 流式传输 flv 文件时,我遇到了这个错误 root@zzz-OptiPlex-170L:~# ffmpeg
我正在尝试压缩一堆文件并通过流使数据可用。 我希望内存占用尽可能小。 我的想法是实现一个 Stream,其中我有一堆 FileStream 对象作为数据成员。当我的 Stream 上的 Read 方法
只是想知道是否有人知道自动执行此操作和/或作为 50 mp4 视频的批处理的脚本或程序。我说的是使用 CLI mediafilesegmenter 命令将视频分段的过程,以便从 Amazon S3 流
我有一个带有摄像头模块的 Raspberry Pi,我想将 PiCamera 的视频返回从 Python 流式传输到另一台运行 Python 服务器的计算机。 我成功地使用 OpenCV 返回了视频(
我正在使用 ffmpeg sdk 在 youtube live 上流式传输实时视频 av_interleaved_write_frame(m_pAvFmtCntx, pkt); av_interlea
我正在尝试使用 Tweepy 流式传输 Twitter,我想知道是否可以在不提供关键字的情况下进行流式传输?因此,我将能够流式传输所有推文,而不仅仅是具有给定关键字的推文。我正在关注的代码可以在这里找
我是 Hazelcast 的新手,我正在尝试使用它来将数据存储在太大而无法容纳在单台计算机上的 map 中。 我需要实现的过程之一是检查 map 中的每个值并对其执行某些操作 - 不是累积或聚合,而且
我需要设置从多个网络摄像头到互联网(在浏览器中)的实时流传输,并且这些流应该仅对特定用户可见。 IE。用户 A 使用他或她的登录名/密码登录我的系统,转到视频流页面,并查看来自特定摄像头的流,而其他用
我在看 Twitter Streaming API获取实时提要。但我不希望它存储在我的服务器上。我只是希望它从服务器中提取,浏览器页面将从我的服务器的 twitter 提取 URL 检索数据。但我想避
我想创建一个P2P视频传输的应用程序。更详细地说,我需要以下内容: 用户可以通过点击应用程序中的按钮来打开网络摄像头。 应用程序开始从网络摄像头拍摄图像并将其发送到特定位置(由端口和 IP 地址指定)
我们有一个在 Tomcat 下运行的 Java Web 应用程序(应用程序 #1)。 我们的要求:我们想为流媒体设置一个单独的服务器。我们的媒体文件已经转换为 flv(我们支持的唯一格式)...我们只
我是 RTMP 流媒体的新手,正在寻求帮助。足以让我开始。 我已经在谷歌上搜索了大约 5-7 个小时,但仍然无法确定我的答案! Red5的文档有限,根本找不到任何支持!甚至与我类似的问题在 stack
我正在尝试编写一个简单的 map only hadoop streaming job 从 hdfs 读取数据并将其推送到 vertica。 我写了几个shell脚本如下 加载.sh hadoop
我是 Android 的新手,正在尝试: 从相机流式传输原始数据 (ImageFormat RAW_SENSOR) 处理原始数据 交互显示处理结果 原始数据捕获似乎只能在静态捕获模式下使用。这是正确的
我需要将音频从麦克风流式传输到 http 服务器。 这些录音设置是我需要的: NSDictionary *audioOutputSettings = [NSDictionary dictionaryW
我需要了解 WCF 在发送消息时是如何工作的。 WCF 在发送之前是否序列化所有内容? 我的另一个问题是使用 Streaming 有什么好处?更大的消息是否更好,比如说 1Mb 到 2Mb?我可以发送
是否可以直接从 API 初始化新的环聊直播广播/流式传输?我尝试将环聊直播用于我网站的直播系统,但我在 YouTube Live API 中没有看到任何允许通过环聊直播创建流的 API 方法(看起来需
我是一名优秀的程序员,十分优秀!