Hi everybody,
I really need some help after spending a lot of time trying to solve my problem. First of all, I have to precise that I’m not a developer and my programmation knowledge is quit limited.
I need to develop an app that launch a video and light on a LED at the same time. App containts three screens : home screen (or menu) on which there will be two images / one screen for the “gare” video / another one for the “mas” video.
I’m using IOIO-OTG board to do that. I already developed the app based on the primary example, HelloIOIO, that create a togglebutton to power the “state light” on the board.
I tested the app with the bridge connection, it means that the phone and the board are connected through the computer and I launch the app from Android Studio. Everything works fine, videos are played and LEDs turn on.
But I discovered that using the final conection I want, meaning the phone connected to the IOIO board with the OTG cable, I launch the app on the phone (sometimes it freezes) and the LEDs stay off.
I am desperate, I can’t find the solution after hours and hours of testing and web searching. I already said that, but unfortunetely, I’m no dev and I’ll not have the time to start a Java learning from scratch (although I’d like to)…
I thought the best solution was to show you the code, as it surely has a great amount of problems I can’t see ! :S
On MainAcitvity :
lanceurgare = ImageView that launch ActivityGare when clicked (for the “gare” video)
lanceurmas = ImageView that launch ActivityMas when clicked (for the “mas” video")
package com.example.recreationappioio;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private ImageView lanceurgare;
private ImageView lanceurmas;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lanceurgare = (ImageView) findViewById(R.id.lanceurgare);
lanceurgare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), ActivityGare.class);
startActivity(otherActivity);
finish();
}
});
lanceurmas = (ImageView) findViewById(R.id.lanceurmas);
lanceurmas.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), ActivityMas.class);
startActivity(otherActivity);
finish();
}
});
}
}
On ActivityGare :
I left the basic comments from IOIO. The LED is connected to pin 11.
package com.example.recreationappioio;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
import ioio.lib.api.DigitalOutput;
import ioio.lib.api.IOIO;
import ioio.lib.api.IOIO.VersionType;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
public class ActivityGare extends IOIOActivity {
/**
* This is the thread on which all the IOIO activity happens. It will be run
* every time the application is resumed and aborted when it is paused. The
* method setup() will be called right after a connection with the IOIO has
* been established (which might happen several times!). Then, loop() will
* be called repetitively until the IOIO gets disconnected.
*/
class Looper extends BaseIOIOLooper {
/** The on-board LED. */
private DigitalOutput led_;
/**
* Called every time a connection with IOIO has been established.
* Typically used to open pins.
*/
@Override
protected void setup() throws ConnectionLostException {
showVersions(ioio_, "IOIO connecté !");
led_ = ioio_.openDigitalOutput(11,true);
//enableUi(true);
}
/**
* Called repetitively while the IOIO is connected.
*
* @throws ConnectionLostException
* When IOIO connection is lost.
* @throws InterruptedException
* When the IOIO thread has been interrupted.
*
* @see ioio.lib.util.IOIOLooper#loop()
*/
@Override
public void loop() throws ConnectionLostException, InterruptedException {
led_.write(true);
Thread.sleep(100);
}
/**
* Called when the IOIO is disconnected.
*
* @see ioio.lib.util.IOIOLooper#disconnected()
*/
@Override
public void disconnected() {
//enableUi(false);
toast("IOIO déconnecté !");
}
/**
* Called when the IOIO is connected, but has an incompatible firmware version.
*
* @see ioio.lib.util.IOIOLooper#incompatible(IOIO)
*/
@Override
public void incompatible() {
showVersions(ioio_, "Incompatible firmware version!");
}
}
/**
* A method to create our IOIO thread.
*
*/
@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
private void showVersions(IOIO ioio, String title) {
toast(String.format("%s\n" +
"IOIOLib: %s\n" +
"Application firmware: %s\n" +
"Bootloader firmware: %s\n" +
"Hardware: %s",
title,
ioio.getImplVersion(VersionType.IOIOLIB_VER),
ioio.getImplVersion(VersionType.APP_FIRMWARE_VER),
ioio.getImplVersion(VersionType.BOOTLOADER_VER),
ioio.getImplVersion(VersionType.HARDWARE_VER)));
}
private void toast(final String message) {
final Context context = this;
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_video);
VideoView videoView = findViewById(R.id.video_viewok);
String videoPath = "android.resource://" + getPackageName() + "/" + R.raw.gare;
Uri uri = Uri.parse(videoPath);
videoView.setVideoURI(uri);
videoView.start();
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
mediaController.setAnchorView(videoView);
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Intent otherActivity = new Intent(getApplicationContext(), MainActivity.class);
startActivity(otherActivity);
finish();
}
});
}
}
ActivityMas is built exactly on the same model, I simply changed pin 11 to 13.
I know it’s a lot of reading but I don’t know what to do anymore. Thanks in advance for all the help and advices you can give me !