/

Android SDK Publisher


  1. Right-click on the app/src/main folder in the Project Explorer and select New > Fragment > Fragment (Blank)
  2. Name the fragment PublishFragment which will update the layout name to fragment_publish
  3. Click Finish
  4. With the PublishFragment file open, remove most of the automated cruft so we have the following

    import android.hardware.Camera;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    import android.widget.Button;
    
    import com.red5pro.streaming.R5Connection;
    import com.red5pro.streaming.R5Stream;
    import com.red5pro.streaming.R5StreamProtocol;
    import com.red5pro.streaming.config.R5Configuration;
    import com.red5pro.streaming.source.R5Camera;
    import com.red5pro.streaming.source.R5Microphone;
    import com.red5pro.streaming.R5Stream.RecordType;
    
    public class PublishFragment extends Fragment {
    
      public static PublishFragment newInstance() {
        PublishFragment fragment = new PublishFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
      }
    
      public PublishFragment() {
        // Required empty public constructor
      }
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      }
    
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_publish, container, false);
        return v;
      }
    
    }
  5. Update the getItem method of the SectionsPagerAdapter in StreamingActivity

     @Override
    public Fragment getItem(int position) {
      switch(position) {
        case 0:
          return PublishFragment.newInstance();
      }
      // getItem is called to instantiate the fragment for the given page.
      // Return a PlaceholderFragment (defined as a static inner class below).
      return PlaceholderFragment.newInstance(position + 1);
    }
  6. Open the fragment_publish.xml file, change the Layout to RelativeLayout and add a SurfaceView and Button control

    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.infrared5.streaming.sample.red5prostreamexample.PublishFragment">
    
      <SurfaceView
        android:id="@+id/surfaceView"
        android:layout_width="320px"
        android:layout_height="240px"
        android:layout_centerInParent="true"
        android:scaleX="1"
        android:scaleY="1"
        />
    
      <Button
        android:id="@+id/publishButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="start"
        android:layout_marginBottom="0dp"
        android:layout_alignParentBottom="true"
        />
    
    </RelativeLayout>