Android Open Source - Android-Media-Helper Image Uploader Fragment Video






From Project

Back to project page Android-Media-Helper.

License

The source code is released under:

Apache License

If you think the Android project Android-Media-Helper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright 2011-2013 Sherif elKhatib//  ww w  .j  a v  a2s . co m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package mobi.sherif.example.imageuploader;

import mobi.sherif.imageuploader.MediaEngine;
import android.app.Fragment;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.VideoView;

/**
 * @author Sherif elKhatib (sherif.elkhatib[at]gmail[dot]com)
 */
public class ImageUploaderFragmentVideo extends Fragment implements MediaEngine.MediaChooseCallback, MediaEngine.LoadingListener {
  MediaEngine uploadEngine;

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uploadEngine = new MediaEngine.Builder(this, savedInstanceState).setLoadingListener(this).build();
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    uploadEngine.onSaveInstanceState(outState);
  }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (uploadEngine.onActivityResult(requestCode, resultCode, data)) return;
    super.onActivityResult(requestCode, resultCode, data);
  }

  @Override
  public void onResult(MediaEngine engine, MediaEngine.Result result) {
    if (result.isError()) {
      if (result.isCanceled()) {
        onCanceled(engine);
      } else {
        onError(engine, result.getException());
      }
    } else {
      onChosen(engine, result.getPath(), result.isNewfile());
    }
  }

  public void onCanceled(MediaEngine engine) {
    mTextView.setText("Canceled");
  }

  public void onChosen(MediaEngine engine, String path, boolean newPicture) {
    mTextView.setText( ( newPicture ? "New" : "Existing" ) + ": " + path);
    mVideoView.setVideoPath(path);
  }

  public void onError(MediaEngine engine, Exception ex) {
    mTextView.setText("Error: " + ex.getMessage());
  }

  @Override
  public void onLoadingStarted( ) {
    mProgress.setVisibility(View.VISIBLE);
  }

  @Override
  public void onLoadingDone( ) {
    mProgress.setVisibility(View.GONE);
  }

  VideoView mVideoView;
  TextView mTextView;
  View mProgress;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.choosevideo, container, false);
    mProgress = v.findViewById(R.id.progress);
    mVideoView = (VideoView) v.findViewById(R.id.video);
    mTextView = (TextView) v.findViewById(R.id.textvideo);
    v.findViewById(R.id.button).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        uploadEngine.performVideoAsk(R.string.app_name, R.string.newvideo, R.string.oldvideo, R.string.choosevideo, R.drawable.ic_launcher);
      }
    });
    ( (VideoView) v.findViewById(R.id.video) ).setOnPreparedListener(new OnPreparedListener() {
      @Override
      public void onPrepared(MediaPlayer mp) {
        mp.start();
      }
    });
    return v;
  }
}




Java Source Code List

mobi.sherif.example.imageuploader.ActivityForFragmentSupportVideo.java
mobi.sherif.example.imageuploader.ActivityForFragmentSupport.java
mobi.sherif.example.imageuploader.ActivityForFragmentVideo.java
mobi.sherif.example.imageuploader.ActivityForFragment.java
mobi.sherif.example.imageuploader.ImageUploaderActivitySupportVideo.java
mobi.sherif.example.imageuploader.ImageUploaderActivitySupport.java
mobi.sherif.example.imageuploader.ImageUploaderActivityVideo.java
mobi.sherif.example.imageuploader.ImageUploaderActivity.java
mobi.sherif.example.imageuploader.ImageUploaderFragmentSupportVideo.java
mobi.sherif.example.imageuploader.ImageUploaderFragmentSupport.java
mobi.sherif.example.imageuploader.ImageUploaderFragmentVideo.java
mobi.sherif.example.imageuploader.ImageUploaderFragment.java
mobi.sherif.example.imageuploader.MainActivity.java
mobi.sherif.imageuploader.ActivityManager.java
mobi.sherif.imageuploader.DefaultFileCreator.java
mobi.sherif.imageuploader.DefaultImageFileCreator.java
mobi.sherif.imageuploader.DefaultVideoFileCreator.java
mobi.sherif.imageuploader.FileLoadTask.java
mobi.sherif.imageuploader.FragmentSupportYesNoDialog.java
mobi.sherif.imageuploader.FragmentYesNoDialogBuilder.java
mobi.sherif.imageuploader.FragmentYesNoDialog.java
mobi.sherif.imageuploader.MediaEngine.java