Example usage for android.widget MediaController setAnchorView

List of usage examples for android.widget MediaController setAnchorView

Introduction

In this page you can find the example usage for android.widget MediaController setAnchorView.

Prototype

public void setAnchorView(View view) 

Source Link

Document

Set the view that acts as the anchor for the control view.

Usage

From source file:com.chute.android.photopickerplustutorial.activity.VideoPlayerActivity.java

private void initVideo(String url) {
    videoView = (VideoView) findViewById(R.id.videoView);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    Uri uri = Uri.parse(url);//from   ww w .jav a 2s . c  om
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.sign_video_view.AbstractSignVideoFragment.java

private void initializeMediaController() {
    final MediaController mediaController = new MediaController(getActivity(), false);
    mediaController.setAnchorView(this.videoView);
    this.videoView.setMediaController(mediaController);
}

From source file:sample.videoview.kevalpatel.com.userawarevideoview.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //set the is tracking indicator
    mTrackingStatusIv = (ImageView) findViewById(R.id.eye_tracking);
    mTrackingStatusIv.setVisibility(View.GONE);

    //set user aware video view
    mVideoView = (UserAwareVideoView) findViewById(R.id.video_view);
    mVideoView.setUserAwarenessListener(this);
    mVideoView.setVideoURI(Uri.parse("http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"));

    //attach tge media controller
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(mVideoView);
    mediaController.setPrevNextListeners(new View.OnClickListener() {
        @Override//  www  .  j av  a2 s .c  om
        public void onClick(View view) {
            mVideoView.stopPlayback();
            mVideoView.start();
        }
    }, new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mVideoView.stopPlayback();
            mVideoView.start();
        }
    });

    mVideoView.setMediaController(mediaController);

    //Start video playing. This will start the user eye tracking too.
    //Do not care about permissions. Permissions will check internally.
    //Just handle errors.
    mVideoView.start();
}

From source file:nz.ac.auckland.lablet.script.components.CameraExperiment.java

public ScriptComponentCameraExperimentView(Context context, ScriptComponentSheetFragment sheetFragment,
        CameraExperiment cameraComponent) {
    super(context, sheetFragment, cameraComponent);
    this.cameraComponent = cameraComponent;

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.script_component_camera_experiment, null, false);
    assert view != null;

    addView(view);//  ww w .  j  av  a  2  s  .co m

    TextView descriptionTextView = (TextView) view.findViewById(R.id.descriptionText);
    assert descriptionTextView != null;
    if (!cameraComponent.getDescriptionText().equals(""))
        descriptionTextView.setText(cameraComponent.getDescriptionText());

    Button takeExperiment = (Button) view.findViewById(R.id.takeExperimentButton);
    assert takeExperiment != null;
    takeExperiment.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            startExperimentActivity(new CameraSensorPlugin());
        }
    });

    videoView = (VideoView) view.findViewById(R.id.videoView);
    assert videoView != null;
    // Don't show a "Can't play this video." alert.
    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            return true;
        }
    });
    MediaController mediaController = new MediaController(context);
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);

    takenExperimentInfo = (CheckedTextView) view.findViewById(R.id.takenExperimentInfo);
    assert takenExperimentInfo != null;

    if (!cameraComponent.getExperiment().getExperimentPath().equals(""))
        onExperimentPerformed();
}

From source file:com.ariesmcrae.mymemories.ui.story.StoryViewFragment.java

public void setUiToStoryData(long getUniqueKey) throws RemoteException {
    Log.d(LOG_TAG, "setUiToStoryData");
    storyData = resolver.getStoryDataViaRowID(getUniqueKey);

    if (storyData == null) {
        getView().setVisibility(View.GONE);
    } else { // else it just displays empty screen
        Log.d(LOG_TAG, "setUiToStoryData + storyData:" + storyData.toString());
        titleTV.setText(String.valueOf(storyData.title).toString());
        bodyTV.setText(String.valueOf(storyData.body).toString());

        audioButton.setOnClickListener(new OnClickListener() {
            @Override//from www. j a  va 2s  .c  o m
            public void onClick(View v) {
                String audioLinkPath = String.valueOf(storyData.audioLink).toString();

                if (audioLinkPath != null && audioLinkPath.length() > 0) {
                    Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), Uri.parse(audioLinkPath));

                    if (!ringtone.isPlaying()) {
                        ringtone.play();
                    }
                }
            }
        });

        // Display the video
        String videoLinkPath = String.valueOf(storyData.videoLink).toString();

        if (videoLinkPath != null && videoLinkPath.length() > 0) {
            MediaController mediaController = new MediaController(getActivity());
            mediaController.setAnchorView(videoLinkView);
            videoLinkView.setMediaController(mediaController);
            videoLinkView.setVideoURI(Uri.parse(videoLinkPath));

            if (!videoLinkView.isPlaying()) {
                videoLinkView.start();
            }
        }

        // Display the image data
        imageNameTV.setText(String.valueOf(storyData.imageName).toString());

        String imageMetaDataPath = String.valueOf(storyData.imageLink).toString();
        imageMetaDataView.setImageURI(Uri.parse(imageMetaDataPath));

        Long time = Long.valueOf(storyData.storyTime);
        storyTimeTV.setText(StoryData.FORMAT.format(time));

        latitudeTV.setText(Double.valueOf(storyData.latitude).toString());
        longitudeTV.setText(Double.valueOf(storyData.longitude).toString());
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.AttachmentViewerActivity.java

@SuppressLint({ "SetJavaScriptEnabled" })
protected void updateView(boolean isUpdate) {
    T.UI();/*from w  w w . jav a  2s.c o m*/

    if (!isUpdate && mGenerateThumbnail) {
        File thumbnail = new File(mFile.getAbsolutePath() + ".thumb");
        if (!thumbnail.exists()) {
            boolean isImage = mContentType.toLowerCase(Locale.US).startsWith("image/");
            boolean isVideo = !isImage && mContentType.toLowerCase(Locale.US).startsWith("video/");
            try {
                // Try to generate a thumbnail
                mMessagingPlugin.createAttachmentThumbnail(mFile.getAbsolutePath(), isImage, isVideo);
            } catch (Exception e) {
                L.e("Failed to generate attachment thumbnail", e);
            }
        }
    }

    final String fileOnDisk = "file://" + mFile.getAbsolutePath();

    if (mContentType.toLowerCase(Locale.US).startsWith("video/")) {
        MediaController mediacontroller = new MediaController(this);
        mediacontroller.setAnchorView(mVideoview);

        Uri video = Uri.parse(fileOnDisk);
        mVideoview.setMediaController(mediacontroller);
        mVideoview.setVideoURI(video);

        mVideoview.requestFocus();
        mVideoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mVideoview.start();
            }
        });

        mVideoview.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                L.e("Could not play video, what " + what + ", extra " + extra + ", content_type " + mContentType
                        + ", and url " + mDownloadUrl);

                AlertDialog.Builder builder = new AlertDialog.Builder(AttachmentViewerActivity.this);
                builder.setMessage(R.string.error_please_try_again);
                builder.setCancelable(true);
                builder.setTitle(null);
                builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        dialog.dismiss();
                        finish();
                    }
                });
                builder.setPositiveButton(R.string.rogerthat, new SafeDialogInterfaceOnClickListener() {
                    @Override
                    public void safeOnClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        finish();
                    }
                });
                builder.create().show();
                return true;
            }
        });

    } else if (CONTENT_TYPE_PDF.equalsIgnoreCase(mContentType)) {
        WebSettings settings = mWebview.getSettings();
        settings.setJavaScriptEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            settings.setAllowUniversalAccessFromFileURLs(true);
        }

        mWebview.setWebViewClient(new WebViewClient() {

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
                if (fileOnDisk.equals(url)) {
                    return null;
                }
                L.d("404: Expected: '" + fileOnDisk + "'\n Received: '" + url + "'");
                return new WebResourceResponse("text/plain", "UTF-8", null);
            }
        });
        try {
            mWebview.loadUrl("file:///android_asset/pdfjs/web/viewer.html?file="
                    + URLEncoder.encode(fileOnDisk, "UTF-8"));
        } catch (UnsupportedEncodingException uee) {
            L.bug(uee);
        }
    } else {
        WebSettings settings = mWebview.getSettings();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            settings.setAllowFileAccessFromFileURLs(true);
        }
        settings.setBuiltInZoomControls(true);
        settings.setLoadWithOverviewMode(true);
        settings.setUseWideViewPort(true);

        if (mContentType.toLowerCase(Locale.US).startsWith("image/")) {
            String html = "<html><head></head><body><img style=\"width: 100%;\" src=\"" + fileOnDisk
                    + "\"></body></html>";
            mWebview.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
        } else {
            mWebview.loadUrl(fileOnDisk);
        }
    }
    L.d("File on disk: " + fileOnDisk);
}

From source file:com.fa.imaged.activity.DetailActivityV2.java

private void PlayVideo() {
    try {/* w  ww.  jav  a 2 s.  c o m*/
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(detailVideoV2);
        detailVideoV2.setVisibility(View.VISIBLE);
        Uri video = Uri.parse(detailImageLoaderv2.video_standard_res);
        detailVideoV2.setMediaController(mediaController);
        detailVideoV2.setVideoURI(video);
        detailVideoV2.requestFocus();
        detailVideoV2.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            public void onPrepared(MediaPlayer mp) {
                detailImageV2.setVisibility(View.GONE);
                detailVideoV2.start();
            }
        });

    } catch (Exception e) {
        System.out.println("Video Play Error :" + e.toString());
    }

}

From source file:jupiter.broadcasting.live.holo.JBPlayer.java

public void StartPlay(String path) {
    Progress(true);//from   w w  w .ja v  a  2 s .c  o m
    if (mVideoCastManager.isConnected()) {
        //casting
        String[] tit_ep;
        tit_ep = title.split("[|]");
        MediaMetadata mMediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
        mMediaMetadata.putString(MediaMetadata.KEY_TITLE, live ? title : tit_ep[0]);
        mMediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, live ? "streaming" : tit_ep[1]);
        mMediaMetadata.putString(MediaMetadata.KEY_STUDIO, "Jupiter Broadcasting");
        mMediaMetadata.addImage(new WebImage(
                Uri.parse("http://jb4.cdn.scaleengine.net/wp-content/themes/jb2014/images/logo.png")));
        mMediaMetadata.addImage(new WebImage(Uri.parse(pic)));
        MediaInfo mSelectedMedia = new MediaInfo.Builder(path)
                .setContentType(live ? "application/x-mpegURL" : "video")
                .setStreamType(live ? MediaInfo.STREAM_TYPE_LIVE : MediaInfo.STREAM_TYPE_BUFFERED)
                .setMetadata(mMediaMetadata).build();
        Progress(false);
        mVideoCastManager.startCastControllerActivity(this, mSelectedMedia, 0, true);
    } else {
        //local playback
        videoView = (VideoView) findViewById(R.id.videoView);
        videoView.setVideoPath(path);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        videoView.setMediaController(mediaController);
        start = true;

        play.setEnabled(false);
        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer player) {

                Toast.makeText(getBaseContext(), "Started", Toast.LENGTH_LONG).show();
                Progress(false);
                int duration = videoView.getDuration();
                iView.setVisibility(View.GONE);
                videoView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
            }
        });
        videoView.start();
        mediaController.show();
    }
}

From source file:com.example.prasadnr.traquad.TraQuad.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tra_quad);
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(TraQuad.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    Builder alert = new AlertDialog.Builder(TraQuad.this);

    WifiManager managerWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    Method[] wmMethods = managerWifi.getClass().getDeclaredMethods();
    for (Method method : wmMethods) {
        if (method.getName().equals("isWifiApEnabled")) {

            try {
                isWifiAPenabled = (boolean) method.invoke(managerWifi);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();//from w  ww.  ja v a 2 s .  c o  m
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }

    final ProgressDialog pDialog;
    MediaController mediaController = new MediaController(this);

    pDialog = new ProgressDialog(TraQuad.this);
    pDialog.setTitle("TraQuad app (Connecting...)");
    pDialog.setMessage("Buffering...Please wait...");
    pDialog.setCancelable(true);

    if (!isWifiAPenabled) {

        alert.setTitle("WiFi Hotspot Settings");
        alert.setMessage("Can you please connect WiFi-hotspot?");
        alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                irritation = true;
                startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                pDialog.show();
            }
        });
        alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //Dismiss AlertDialog
                pDialog.show();
                Toast.makeText(getApplicationContext(), "Please connect your WiFi!", Toast.LENGTH_LONG).show();
            }
        });
        alert.setCancelable(false);
        AlertDialog alertDialog = alert.create();
        alertDialog.show();
    }

    WebView webView = (WebView) findViewById(R.id.webView);

    if (irritation == true | isWifiAPenabled) {
        pDialog.show();
    }

    mediaController.setAnchorView(webView);
    mediaController.setVisibility(View.GONE);

    extra = getIntent().getStringExtra("VideosId");
    webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);

    final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
    final String IPaddressNew = globalVariable.getIP();
    final String httpString = "http://";
    final String commandPort = String.valueOf(1500);
    final String streamPort = String.valueOf(8080);
    final String IPaddressStream = httpString + IPaddressNew + ":" + streamPort;
    final String IPaddressCommand = httpString + IPaddressNew + ":" + commandPort;
    TextView sendCharacter = (TextView) findViewById(R.id.sendCharacter);

    try {
        webView.loadUrl(IPaddressStream);
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), IPaddressNew + ":Error!", Toast.LENGTH_LONG).show();
    }

    webView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            pDialog.dismiss();
        }
    });

    final Button switchact = (Button) findViewById(R.id.btn2);
    switchact.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent act1 = new Intent(view.getContext(), Joypad.class);
            startActivity(act1);

        }
    });

    final Button hometraquad = (Button) findViewById(R.id.button5);

    hometraquad.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent acthometraquad = new Intent(TraQuad.this, MainActivity.class);
            startActivity(acthometraquad);
        }
    });

}