android流媒体之视频流问题
请问有谁碰到过这个问题,怎么解决的?请高人解答一下
04-28 04:45:19.088: D/AndroidRuntime(619): Shutting down VM
04-28 04:45:19.088: W/dalvikvm(619): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-28 04:45:19.094: E/AndroidRuntime(619): FATAL EXCEPTION: main
04-28 04:45:19.094: E/AndroidRuntime(619): java.lang.IllegalStateException: Could not execute method of the activity
04-28 04:45:19.094: E/AndroidRuntime(619): at android.view.View$1.onClick(View.java:2072)
04-28 04:45:19.094: E/AndroidRuntime(619): at android.view.View.performClick(View.java:2408)
04-28 04:45:19.094: E/AndroidRuntime(619): at android.view.View$PerformClick.run(View.java:8816)
04-28 04:45:19.094: E/AndroidRuntime(619): at android.os.Handler.handleCallback(Handler.java:587)
04-28 04:45:19.094: E/AndroidRuntime(619): at android.os.Handler.dispatchMessage(Handler.java:92)
04-28 04:45:19.094: E/AndroidRuntime(619): at android.os.Looper.loop(Looper.java:123)
04-28 04:45:19.094: E/AndroidRuntime(619): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-28 04:45:19.094: E/AndroidRuntime(619): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 04:45:19.094: E/AndroidRuntime(619): at java.lang.reflect.Method.invoke(Method.java:521)
04-28 04:45:19.094: E/AndroidRuntime(619): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-28 04:45:19.094: E/AndroidRuntime(619): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-28 04:45:19.094: E/AndroidRuntime(619): at dalvik.system.NativeStart.main(Native Method)
04-28 04:45:19.094: E/AndroidRuntime(619): Caused by: java.lang.reflect.InvocationTargetException
04-28 04:45:19.094: E/AndroidRuntime(619): at com.bangda.mp4test.OnLineMp4TestActivity.play(OnLineMp4TestActivity.java:41)
04-28 04:45:19.094: E/AndroidRuntime(619): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 04:45:19.094: E/AndroidRuntime(619): at java.lang.reflect.Method.invoke(Method.java:521)
04-28 04:45:19.094: E/AndroidRuntime(619): at android.view.View$1.onClick(View.java:2067)
04-28 04:45:19.094: E/AndroidRuntime(619): ... 11 more
04-28 04:45:19.094: E/AndroidRuntime(619): Caused by: java.lang.IllegalArgumentException
04-28 04:45:19.094: E/AndroidRuntime(619): at android.media.MediaPlayer.setDataSource(Native Method)
04-28 04:45:19.094: E/AndroidRuntime(619): ... 15 more
04-28 04:52:05.354: E/MediaPlayer(652): error (1, -2147483648)
04-28 04:52:05.354: D/AndroidRuntime(652): Shutting down VM
04-28 04:52:05.354: W/dalvikvm(652): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-28 04:52:05.365: E/AndroidRuntime(652): FATAL EXCEPTION: main
04-28 04:52:05.365: E/AndroidRuntime(652): java.lang.IllegalStateException: Could not execute method of the activity
04-28 04:52:05.365: E/AndroidRuntime(652): at android.view.View$1.onClick(View.java:2072)
04-28 04:52:05.365: E/AndroidRuntime(652): at android.view.View.performClick(View.java:2408)
04-28 04:52:05.365: E/AndroidRuntime(652): at android.view.View$PerformClick.run(View.java:8816)
04-28 04:52:05.365: E/AndroidRuntime(652): at android.os.Handler.handleCallback(Handler.java:587)
04-28 04:52:05.365: E/AndroidRuntime(652): at android.os.Handler.dispatchMessage(Handler.java:92)
04-28 04:52:05.365: E/AndroidRuntime(652): at android.os.Looper.loop(Looper.java:123)
04-28 04:52:05.365: E/AndroidRuntime(652): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-28 04:52:05.365: E/AndroidRuntime(652): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 04:52:05.365: E/AndroidRuntime(652): at java.lang.reflect.Method.invoke(Method.java:521)
04-28 04:52:05.365: E/AndroidRuntime(652): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-28 04:52:05.365: E/AndroidRuntime(652): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-28 04:52:05.365: E/AndroidRuntime(652): at dalvik.system.NativeStart.main(Native Method)
04-28 04:52:05.365: E/AndroidRuntime(652): Caused by: java.lang.reflect.InvocationTargetException
04-28 04:52:05.365: E/AndroidRuntime(652): at com.bangda.mp4test.OnLineMp4TestActivity.play(OnLineMp4TestActivity.java:48)
04-28 04:52:05.365: E/AndroidRuntime(652): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 04:52:05.365: E/AndroidRuntime(652): at java.lang.reflect.Method.invoke(Method.java:521)
04-28 04:52:05.365: E/AndroidRuntime(652): at android.view.View$1.onClick(View.java:2067)
04-28 04:52:05.365: E/AndroidRuntime(652): ... 11 more
04-28 04:52:05.365: E/AndroidRuntime(652): Caused by: java.io.IOException: Prepare failed.: status=0x1
04-28 04:52:05.365: E/AndroidRuntime(652): at android.media.MediaPlayer.prepare(Native Method)
04-28 04:52:05.365: E/AndroidRuntime(652): ... 15 more
--------------------编程问答-------------------- 报的还是很清楚的:MediaPlayer.setDataSource()参数不对,检查一下参数;
还没正确执行setDataSource()进入Initialized状态之前,当然prepare()也是不对的。
另,播放流媒体用prepareAsync()异步方式。 --------------------编程问答-------------------- 要按状态机描述的来写 --------------------编程问答-------------------- 后来出现这个错误提示,我对流媒体没有什么研究,看不懂这个是什么意思,请问能解释一下吗?或者怎么解决这个异常。
04-28 08:38:14.034: E/MediaPlayer(952): start called in state 4
04-28 08:38:14.034: E/MediaPlayer(952): error (-38, 0)
04-28 08:38:14.034: E/MediaPlayer(952): Error (-38,0)
04-28 08:38:14.555: E/MediaPlayer(952): error (1, -2147483648)
04-28 08:38:14.555: E/MediaPlayer(952): Error (1,-2147483648)
--------------------编程问答-------------------- 搞了好几天都不能解决,我把源码发出来大家看看,这个异常怎么解决
代码如下:
import java.io.IOException;
import java.net.UnknownHostException;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Environment;
import android.view.Su易做图ceHolder;
import android.view.View;
public class OnLineMp4TestActivity extends Activity implements
Su易做图ceHolder.Callback{
android.media.MediaPlayer player;
android.view.Su易做图ceView su易做图ceView;
android.view.Su易做图ceHolder su易做图ceholder;
String strFilePath = "";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
su易做图ceView = (android.view.Su易做图ceView) findViewById(R.id.su易做图ceview);
su易做图ceholder = su易做图ceView.getHolder();
su易做图ceholder.addCallback(this);
su易做图ceholder.setFixedSize(176, 144);
su易做图ceholder.setType(su易做图ceholder.SURFACE_TYPE_PUSH_BUFFERS);
getWindow().setFormat(PixelFormat.UNKNOWN);
}
public void play(View view) throws IllegalArgumentException, IllegalStateException, IOException, InterruptedException {
System.out.println("play");
addMovie();
player = new android.media.MediaPlayer();
player.setDataSource(saveFile);
player.setAudioStreamType(android.media.AudioManager.STREAM_MUSIC);
player.setScreenOnWhilePlaying(true);
player.setDisplay(su易做图ceholder);
player.prepareAsync();
player.start();
}
java.net.Socket socket;
String saveFile;
java.io.DataInputStream din;
java.io.DataOutputStream dout;
java.io.File temp;
private void addMovie() throws InterruptedException {
new Thread() {
public void run() {
try {
socket = new java.net.Socket("10.0.2.2", 8888);
if (socket.isConnected()) {
System.out.println("连接成功!");
din = new java.io.DataInputStream(
new java.io.BufferedInputStream(
socket.getInputStream()));
dout = new java.io.DataOutputStream(
new java.io.BufferedOutputStream(
socket.getOutputStream()));
dout.writeUTF("<#Movie#>");
dout.flush();
String msg=din.readUTF();
if(msg.startsWith("<#New_Movie_File#>")){
System.out.println(msg);
msg=msg.substring(18);
String[] sa=msg.split(",");
saveFile =Environment.getExternalStorageDirectory()+ java.io.File.separator
+ sa[0];
System.out.println(saveFile);
java.io.File file = new java.io.File(saveFile);
java.io.FileOutputStream fout = new java.io.FileOutputStream(
file);
java.io.DataOutputStream fdout = new java.io.DataOutputStream(
new java.io.BufferedOutputStream(fout));
byte[] bys = new byte[16];
int fileSize = Integer.valueOf(sa[1]);
System.out.println("UpLoadFileActivity-接收文件的大小:"
+ fileSize);
int currSize = 0;
int count = 0;
while (currSize < fileSize && count != -1) {
count = din.read(bys);
if (count > -1) {
fdout.write(bys, 0, count);
fdout.flush();
currSize += count;
//System.out.println("文件当前传送长度:"+count);
//System.out.println("文件当前传送总长度:"+currSize);
}
}
System.out.println("文件接收完毕!当前接收文件长度:" + currSize);
fdout.close();
dout.writeUTF("<#Success_Music#>");
dout.flush();
}
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
Thread.sleep(1000);
}
@Override
public void su易做图ceChanged(Su易做图ceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void su易做图ceCreated(Su易做图ceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public void su易做图ceDestroyed(Su易做图ceHolder holder) {
// TODO Auto-generated method stub
}
}
补充:移动开发 , Android