Question

I am trying to make a android plugin for unity.

I have an activity that I start manually like this:

    Activity activity = UnityPlayer.currentActivity;
    Intent intent = new Intent(activity, VideoHelper.class);
    activity.startActivity(intent);

In the activity I try to create a SurfaceView, but it is not working. The SurfaceView is not created.

Activity:

public class VideoHelper extends Activity implements SurfaceHolder.Callback, OnCompletionListener
{
    @Override
    public void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);

        setContentView(R.layout.video_layout);

        View view = findViewById(R.id.videoView);
        if(view == null)
        {
            Log.d(LibraryMain.LogTag, "Could not create view");
        }
        else
        {
            Log.d(LibraryMain.LogTag, "View created");
        }
        //SurfaceHolder holder = view.getHolder();
        //holder.addCallback(this);
    }
    ...
}

video_layout.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    <SurfaceView android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:id="@+id/videoView"></SurfaceView>

</LinearLayout>

I always get to the log of Could not create view. Am I doing something wrong? Or is there maybe a way to create a surfaceView though code?

Was it helpful?

Solution

I have managed to get it working.

public void onCreate(Bundle bundle)
{
    super.onCreate(bundle);

    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    _surface = (SurfaceView)inflater.inflate(R.layout.video_layout, null);

    SurfaceHolder holder = _surface.getHolder();
    holder.addCallback(this);

    addContentView(_surface, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top