-1

I want to pass the SurfaceView from activity to service using AIDL. In Service I will be rendering the video.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kiran Biradar
  • 12,700
  • 3
  • 19
  • 44

4 Answers4

2

Found the solution, Instead of passing surface view application can pass the Surface which actually implements parcelable interface and instance of Surface class can be passed to MediaPlayer.setSurface() to render the Video.

In .aidl file

import android.view.Surface;

oneway interface{
void startRender( in Surface surface)
}

in Service

    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.stop();
    mediaPlayer.reset();
    mediaPlayer.setSurface(surfaceViewId);

In application

 serviceInstance.startRender((((SurfaceView)findViewById(R.id.surfaceView)).getHolder()).getSurface());
kiran Biradar
  • 12,700
  • 3
  • 19
  • 44
1

Only one solution is there, But you need to use singleton surfaceview and make sure you don't have any UI leaks in your implmentation. And one thing, you need to reinitialize everytime whereever you use surfaceview. Whenever you move out from activity and service where surfaceview already got initialized will get destroyed. Because surfaceview/surface taken by windowmanager.

RajeshVijayakumar
  • 10,281
  • 11
  • 57
  • 84
0

You cannot pass surfaceview using AIDL . Only certain data types,list and map are supported by default. You can also parcel custom objects but surfaceview is not one of them. More Info.

Dishonered
  • 8,449
  • 9
  • 37
  • 50
0

Service in android is designed to do something in background. If you want to play a video file or stream, use a full screen activity with a VideoView in its layout. Pass the uri of media to VideoView.

Ali Behzadian Nejad
  • 8,804
  • 8
  • 56
  • 106