Greetings community. I'm in a problem I'll start by saying that I do not know if I'm even in the amateur category. Anyway, with a lot of effort, I've made some progress, but I'm stuck. App to play a video on a device. That video shot him doing play from another place (via UDP implemented with ESP8266). Until the play, come. But I need to shoot Pause and Stop. I have not achieved it after several days. Code:
public class DemoActivity extends AppCompatActivity
package com.helap.player360;
{
public static final String sPath = "file://mnt/sdcard/vr/";
private String u;
private UDPUtils udpUtils;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
udpUtils = new UDPUtils(this);
udpUtils.startReceiveUdp();
final EditText et = (EditText) findViewById(R.id.edit_text_url);
SparseArray<String> data = new SparseArray<>();
data.put(data.size(), sPath + "XXX.mp4");
{
@Override
public void onSpinnerClicked(int index, int key, String value)
{
et.setText(value);
u = value;
}
}).init(R.id.spinner_url);
findViewById(R.id.sync_button).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
//MD360PlayerActivity.startVideo(DemoActivity.this, Uri.parse(u));
SendMessage("192.168.0.25", "SYNC");
}
});
}
This block works well, without problems. Now the interface class, the next one, which also works.
package com.helap.player360;
public class UDPUtils implements AsyncResponse
{
private UDPServer udpServer;
private UDPSender udpSender;
private DemoActivity context;
public int modo;
public UDPUtils(Context context){this.context=(DemoActivit)context;}
@Override
public void processFinish(final String output)
{
context.runOnUiThread(new Runnable()
{
@Override
public void run()
{
if(output.equals("200"))
{
context.sync();
}
if(output.equals("300"))
{
context.start();
}
if(output.equals("400"))
{
modo = 3;
//context.pausa();
}
}
});
}
/** Start UDP server as asynctask **/
void startReceiveUdp()
{
if (udpServer == null)
{
udpServer = new UDPServer();
udpServer.setPort(8888);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
udpServer.delegate = this;
udpServer.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
else
{
udpServer.execute();
}
}
}
interface AsyncResponse
{
void processFinish(String output);
}
A class that I understand is an interface between the initiation and the ppal
public abstract class MD360PlayerActivity extends Activity
{
private static final SparseArray<String> sDisplayMode = new SparseArray<>();
private static final SparseArray<String> sInteractiveMode = new SparseArray<>();
private static final SparseArray<String> sProjectionMode = new SparseArray<>();
private static final SparseArray<String> sAntiDistortion = new SparseArray<>();
private static final SparseArray<String> sPitchFilter = new SparseArray<>();
private static final SparseArray<String> sFlingEnabled = new SparseArray<>();
int m, n;
static
{
}
public static void startVideo(Context context, Uri uri)
{
start(context, uri, VideoPlayerActivity.class);
}
private static void start(Context context, Uri uri, Class < ? extends Activity > clz)
{
Intent i = new Intent(context, clz);
i.setData(uri);
context.startActivity(i);
}
public void cancelBusy(){findViewById(R.id.progress).setVisibility(View.GONE);}
//*******************************************************************************
private XXXLibrary mXXLibrary;
@Override
public void onCreate(Bundle savedInstanceState)
{
........
}
abstract protected XXXLibrary createXXXLibrary();
public MDVRLibrary getVRLibrary() {return mVRLibrary;}
@Override
protected void onResume()
{
super.onResume();
mVRLibrary.onResume(this);
}
@Override
protected void onPause()
{
super.onPause();
mVRLibrary.onPause(this);
}
@Override
protected void onDestroy()
{
super.onDestroy();
mVRLibrary.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mVRLibrary.onOrientationChanged(this);
}
protected Uri getUri()
{
Intent i = getIntent();
if (i == null || i.getData() == null)
{
return null;
}
return i.getData();
}
}
And finally the class I can not act on.
package com.helap.player360;
import...
public class VideoPlayerActivity extends MD360PlayerActivity
{
private MediaPlayerWrapper mMediaPlayerWrapper = new MediaPlayerWrapper();
private int d;
@Override
public void onCreate(Bundle savedInstanceState)
{
mMediaPlayerWrapper.init();
super.onCreate(savedInstanceState);
mMediaPlayerWrapper.setPreparedListener(new IMediaPlayer.OnPreparedListener()
{
@Override
public void onPrepared(IMediaPlayer mp)
{
cancelBusy();
if (getVRLibrary() != null)
{
getVRLibrary().notifyPlayerChanged();
}
}
});
mMediaPlayerWrapper.getPlayer().setOnErrorListener(new IMediaPlayer.OnErrorListener()
{
@Override
public boolean onError(IMediaPlayer mp, int what, int extra)
{
String error = String.format("Play Error what=%d extra=%d", what, extra);
Toast.makeText(VideoPlayerActivity.this, error, Toast.LENGTH_SHORT).show();
return true;
}
});
mMediaPlayerWrapper.getPlayer().setOnVideoSizeChangedListener(new IMediaPlayer.OnVideoSizeChangedListener()
{
@Override
public void onVideoSizeChanged(IMediaPlayer mp, int width, int height, int sar_num, int sar_den)
{
getVRLibrary().onTextureResize(width, height);
}
});
/********************************************************/
Uri uri = getUri();
if (uri != null)
{
mMediaPlayerWrapper.openRemoteFile(uri.toString());
mMediaPlayerWrapper.prepare();
}
findViewById(R.id.pause).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
mMediaPlayerWrapper.pause();
}
});
findViewById(R.id.button_resume).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
mMediaPlayerWrapper.resume();
}
});
}
//**********************************
@Override
protected void onDestroy()
{
super.onDestroy();
mMediaPlayerWrapper.destroy();
}
@Override
protected void onPause()
{
super.onPause();
mMediaPlayerWrapper.pause();
}
@Override
protected void onResume()
{
super.onResume();
mMediaPlayerWrapper.resume();
}
}
In these last three (protected void on Destroy (), protected void on Pause (), protected void on Resume ()) are the ones I want to act on via UDP with an AsyncTask, and the truth is, I have not succeeded. Any help, will be eternally grateful.