
padde wrote:About the drop frame to stay in sync thingy... MJPEG isnt really
a video codec like others. Its a simple chain of JPEGs seperated
by a delimiter string. There is no information about sync or speed
at all in the stream itself.


package com.test;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class IntentTest extends Activity {
/** Called when the activity is first created. */
ListView myListView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myListView = (ListView)findViewById(R.id.listView);
final ArrayList<String> items = new ArrayList<String>();
items.add("00408C944B9A");
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
items);
myListView.setAdapter(aa);
myListView.setOnItemClickListener(listClicked);
}
private OnItemClickListener listClicked = new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// TODO Auto-generated method stub
Intent i = new Intent(IntentTest.this, OtherActivity.class);
i.putExtra("MAC", myListView.getItemAtPosition(position).toString());
startActivity(i);
}
};
}package com.test;
import com.test.mjpeg.mjpegsample.MjpegView.*;
import com.test.parser.JSONParse;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class OtherActivity extends Activity {
/** Called when the activity is first created. */
private MjpegView mv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null){
String mac = (String)extras.get("MAC");
Log.i("Other", "---->" + mac);
TextView tv = (TextView)findViewById(R.id.textView);
tv.setText(mac);
String URL = "myurl";
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
mv = new MjpegView(this);
setContentView(mv);
mv.setSource(MjpegInputStream.read(URL));
mv.setDisplayMode(MjpegView.SIZE_BEST_FIT);
mv.showFps(true);
}
}
public void onPause() {
super.onPause();
mv.stopPlayback();
}
}



mv.stopPlayback();
mv.setSource(MjpegInputStream.read(Studio));
mv.setDisplayMode(MjpegView.SIZE_BEST_FIT);
mv.showFps(true);

digitalmischief wrote:Hi,
This code is working perfectly apart from one issue, if I have it playing the stream from one camera and then I want to change the source to be from another camera like below:
- Code: Select all
mv.stopPlayback();
mv.setSource(MjpegInputStream.read(Studio));
mv.setDisplayMode(MjpegView.SIZE_BEST_FIT);
mv.showFps(true);
It hangs on the setSource line with exception :
java.lang.IllegalThreadStateException: Thread already started.
I assume this because stopPlayback() has not finalised everything properly, do I need to do something other than just stopPlayback() ?
thanks!

<view
class="com.digitalmischief.housecontrol.MjpegView"
android:id="@+id/mv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<SurfaceView
android:id="@+id/surface_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>
</SurfaceView>mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
mv = new MjpegView(this, mSurfaceView);
public MjpegView(Context context, AttributeSet attrs) {
super(context, attrs); init(context);
}
public MjpegView(Context context, SurfaceView mSurfaceView) { super(); init(context, mSurfaceView); }
public void surfaceCreated(SurfaceHolder holder) { surfaceDone = true; }
public void showFps(boolean b) { showFps = b; }
public void setSource(MjpegInputStream source) { mIn = source; startPlayback();}
public void setOverlayPaint(Paint p) { overlayPaint = p; }
public void setOverlayTextColor(int c) { overlayTextColor = c; }
public void setOverlayBackgroundColor(int c) { overlayBackgroundColor = c; }
public void setOverlayPosition(int p) { ovlPos = p; }
public void setDisplayMode(int s) { displayMode = s; }

Users browsing this forum: Google [Bot] and 10 guests