我遵循这个在android中播放流式广播
这里它的工作很好,但玩家加载有点慢,点击后,我需要等待30秒以上的时间
MediaPlayer: setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: http://www.example.com:8000/live.ogg
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1074)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:927)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:854)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1087)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1061)
at org.oucho.radio.Player.playLaunch(Player.java:237)
at org.oucho.radio.Playlist.onPostExecute(Playlist.java:98)
at org.oucho.radio.Playlist.onPostExecute(Playlist.java:35)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
http://www.example.com:8000/beet.ogg
http://www.example.com:8000/mouthorgan.mp3
http://www.example.com:8000/live
音频正在播放,但在这个错误之后,它需要大约30秒的时间,有些时候,它需要太长的时间....当我播放它,显示这个错误,然后它连接到服务器...和演奏
请帮我把这个修好
java.io.FileNotFoundException:没有内容提供商:http://www.example.com:8000/live.ogg
因为它尝试根据上下文作为文件从设备contentprovider加载,而您是作为URL传递的。
看来你的问题是将数据源设置为MediaPlayer。因为您正在尝试播放url或流,这需要在没有上下文的情况下设置DataSource方法。
public class PlayerScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
startService(new Intent(this, MediaPlayerService.class));
findViewById(R.id.btnChangeTrack).setOnClickListener(clickListener);
findViewById(R.id.btnStartMediaPlayer).setOnClickListener(clickListener);
findViewById(R.id.btnStopMediaPlayer).setOnClickListener(clickListener);
ToggleButton toggleButton = (ToggleButton) findViewById(R.id.togglePauseResume);
toggleButton.setOnCheckedChangeListener(checkedChangeListener);
/*
* To get url which is passing from the previous activity listitem click.
* If url which is pass from listitem click is not empty it will start player
* */
String url = getIntent().getStringExtra("url");
if (!TextUtils.isEmpty(url))
startMediaPlayer(url);
}
private ToggleButton.OnCheckedChangeListener checkedChangeListener = new ToggleButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isChecked) {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.PAUSE_MEDIA_PLAYER);
sendBroadcast(intent);
} else {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.RESUME_MEDIA_PLAYER);
sendBroadcast(intent);
}
}
};
private View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent;
switch (v.getId()) {
case R.id.btnChangeTrack:
intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.CHANGE_PLAYER_TRACK);
intent.putExtra(MediaPlayerService.PLAYER_TRACK_URL, "http://www.example.com:8000/live");
sendBroadcast(intent);
break;
case R.id.btnStartMediaPlayer:
startMediaPlayer("http://www.example.com:8000/beet.ogg");
//startMediaPlayer("http://108.163.197.114:8071/listen.pls");
break;
case R.id.btnStopMediaPlayer:
intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.STOP_MEDIA_PLAYER);
sendBroadcast(intent);
break;
}
}
};
@Override
protected void onResume() {
super.onResume();
registerReceiver(receiverFromservice, new IntentFilter(MediaPlayerService.SERVICE_TO_ACTIVITY));
}
private String currentPlayerStatus = "N/A";
private BroadcastReceiver receiverFromservice = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (MediaPlayerService.SERVICE_TO_ACTIVITY.equalsIgnoreCase(action)) {
/*
* To get current status of player
* */
currentPlayerStatus = intent.getStringExtra(MediaPlayerService.PLAYER_STATUS_KEY);
Log.e("Player Mode", "" + currentPlayerStatus);
}
}
};
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(receiverFromservice);
}
/**
* TO start media player.It will send broadcast to Service & from service player will start
*
* @param url
*/
public void startMediaPlayer(String url) {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.PLAY_MEDIA_PLAYER);
intent.putExtra(MediaPlayerService.PLAYER_TRACK_URL, url);
sendBroadcast(intent);
}
}
public class MediaPlayerService extends Service {
public static final String BROADCAST_TO_SERVICE = "com.mediaplayer.playerfunction";
public static final String SERVICE_TO_ACTIVITY = "com.mediaplayer.currentPlayerStatus";
public static final String PLAYER_FUNCTION_TYPE = "playerfunction";
public static final String PLAYER_TRACK_URL = "trackURL";
public static final int PLAY_MEDIA_PLAYER = 1;
public static final int PAUSE_MEDIA_PLAYER = 2;
public static final int RESUME_MEDIA_PLAYER = 3;
public static final int STOP_MEDIA_PLAYER = 4;
public static final int CHANGE_PLAYER_TRACK = 5;
public static final String PLAYER_STATUS_KEY = "PlayerCurrentStatus";
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
IntentFilter intentFilter = new IntentFilter(BROADCAST_TO_SERVICE);
registerReceiver(playerReceiver, intentFilter);
if (mPlayer != null && mPlayer.isPlaying()) {
sendPlayerStatus("playing");
}
return START_STICKY;
}
private BroadcastReceiver playerReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BROADCAST_TO_SERVICE.equalsIgnoreCase(action)) {
String trackURL = intent.hasExtra(PLAYER_TRACK_URL) ? intent.getStringExtra(PLAYER_TRACK_URL) : "";
int function = intent.getIntExtra(PLAYER_FUNCTION_TYPE, 0);
switch (function) {
case CHANGE_PLAYER_TRACK:
changeTrack(trackURL);
break;
case STOP_MEDIA_PLAYER:
stopPlayer();
break;
case PLAY_MEDIA_PLAYER:
startMediaPlayer(trackURL);
break;
case PAUSE_MEDIA_PLAYER:
pausePlayer();
break;
case RESUME_MEDIA_PLAYER:
resumePlayer();
break;
}
}
}
};
private MediaPlayer mPlayer;
private void pausePlayer() {
if (mPlayer != null && mPlayer.isPlaying()) {
mPlayer.pause();
sendPlayerStatus("pause");
}
}
private void resumePlayer() {
if (mPlayer != null && !mPlayer.isPlaying()) {
mPlayer.start();
sendPlayerStatus("playing");
}
}
private void changeTrack(String url) {
stopPlayer();
startMediaPlayer(url);
}
private void stopPlayer() {
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
mPlayer = null;
sendPlayerStatus("stopped");
}
}
public void startMediaPlayer(String url) {
if (TextUtils.isEmpty(url))
return;
if (mPlayer == null)
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(url);
mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
if (extra == MediaPlayer.MEDIA_ERROR_SERVER_DIED
|| extra == MediaPlayer.MEDIA_ERROR_MALFORMED) {
sendPlayerStatus("erroronplaying");
} else if (extra == MediaPlayer.MEDIA_ERROR_IO) {
sendPlayerStatus("erroronplaying");
return false;
}
return false;
}
});
mPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.e("onBufferingUpdate", "" + percent);
}
});
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mPlayer.start();
sendPlayerStatus("playing");
}
});
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.e("onCompletion", "Yes");
sendPlayerStatus("completed");
}
});
mPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
return false;
}
});
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void sendPlayerStatus(String status) {
Intent intent = new Intent();
intent.setAction(SERVICE_TO_ACTIVITY);
intent.putExtra(PLAYER_STATUS_KEY, status);
sendBroadcast(intent);
}
}
player.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ab_tool"
android:text="Home" />
<Button
android:id="@+id/btnStartMediaPlayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/section_label"
android:text="Start Player" />
<ToggleButton
android:id="@+id/togglePauseResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnStartMediaPlayer"
android:checked="true"
android:textOff="Resume"
android:textOn="Pause" />
<Button
android:id="@+id/btnChangeTrack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/togglePauseResume"
android:text="Chanage Track" />
<Button
android:id="@+id/btnStopMediaPlayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnChangeTrack"
android:text="STOP" />
</RelativeLayout>
清单
<activity android:name=".PlayerScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MediaPlayerService"></service>
public class PlayerScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
startService(new Intent(this, MediaPlayerService.class));
/*
* To get url which is passing from the previous activity listitem click.
* If url which is pass from listitem click is not empty it will start player
* */
String url = getIntent().getStringExtra("url");
if (!TextUtils.isEmpty(url))
startMediaPlayer(url);
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(receiverFromservice, new IntentFilter(MediaPlayerService.SERVICE_TO_ACTIVITY));
}
private String currentPlayerStatus = "N/A";
private BroadcastReceiver receiverFromservice = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (MediaPlayerService.SERVICE_TO_ACTIVITY.equalsIgnoreCase(action)) {
/*
* To get current status of player
* */
currentPlayerStatus = intent.getStringExtra(MediaPlayerService.PLAYER_STATUS_KEY);
Log.e("Player Mode", "" + currentPlayerStatus);
}
}
};
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(receiverFromservice);
}
/**
* TO start media player.It will send broadcast to Service & from service player will start
*
* @param url
*/
public void startMediaPlayer(String url) {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.PLAY_MEDIA_PLAYER);
intent.putExtra(MediaPlayerService.PLAYER_TRACK_URL, url);
sendBroadcast(intent);
}
}
有什么事告诉我。
通常,从图库中选择一个视频并用库剪切,问题是我需要将剪切的视频(它存储在外部存储器:/storage/emulated/0/test_video.mp4中)转换为base64,这就是它失败的地方。我该怎么解决呢?我已经将权限放在清单上,并以编程方式请求这些权限。 而我在logcast中得到的只有:
我想使用gstreamer进行网络传输。目的是启动视频内容(从发射机)并在接收机端播放。我编写了一个用于对网络内容进行流式传输的示例测试代码。 在发射机侧:GST\u DEBUG=“*:2”GST-launch-1.0 videotestsrc!视频/x-raw!jpegenc!rtpjpegpay!udpsink主机=127.0.0.1端口=5001 在接收器端:GST\u DEBUG=“*:2
问题内容: 我正在尝试在html页面中显示配置的值和角值服务中的版本代码,但显示的不是作者的名字,这是html代码 这是指令… 这是在其中配置和值的服务部分 我在开发人员控制台中遇到的错误是 问题答案: 确保将这些模块( myApp.services 和 myApp.directives )作为主要应用程序模块的依赖项加载,如下所示: 塞子: http ://plnkr.co/edit/wxuFx
我目前正在使用MediaPlayer播放来自web的实时流。问题是MediaPlayer缓冲区很大,它坚持在播放前缓冲10秒左右。Android-ICS 4.0中的MediaPlayer缓冲区大小 所以我的问题是,有没有另外一种不用MediaPlayer播放媒体流(mp3)的方法?也许使用InputStream或甚至第三方媒体播放器不会有相同的缓冲问题?
问题内容: 当我有嵌套在根组件下的组件时,我无法实例化我的应用程序,该组件在其构造函数中使用。 我想知道为什么这种行为是非法的。假设我想在班级中使用该类,而只是在班级中引用该类。这似乎是不可能的。 创建层次结构的正确方法是什么? 谢谢你 PLNKR:http ://plnkr.co/edit/5Z0QMAEyZNUAotZ6r7Yi?p=preview 问题答案: 您可以直接将父组件注入到组件中,
我想直播Android麦克风,可以使用VLC播放器等听到。 Playstore主要提供IP摄像头应用,但这些应用是通过内部网络实现的。我想在互联网上播放流媒体。 可能吗? 我尝试了以下代码片段,但目前不起作用: 在VLC播放器前,我试着听(媒体)- 还有别的办法吗?