Search in sources :

Example 1 with Media

use of org.storymaker.app.model.Media in project storymaker by StoryMaker.

the class PreviewVideoView method doPlay.

private void doPlay() {
    Media media = mMediaArray[mCurrentMedia];
    if (media.getDuration() == 0) {
        // old projects didn't save duration, we need it
        media.setDuration(getDuration());
        media.save();
    }
    if ((media.getTrimStart() > 0) && (media.getTrimStart() < 99)) {
        int startTime = media.getTrimmedStartTime();
        seekTo(startTime);
    }
    if ((media.getTrimEnd() != 0) && (media.getTrimEnd() < 99)) {
        // && (media.getTrimStart() < media.getTrimEnd())) {
        mHandler.removeCallbacks(mTrimClipEndTask);
        int duration = media.getTrimmedDuration();
        mHandler.postDelayed(mTrimClipEndTask, duration);
    }
    start();
// FIXME make sure to kill off the timer if we close the activity/stop
}
Also used : Media(org.storymaker.app.model.Media)

Example 2 with Media

use of org.storymaker.app.model.Media in project storymaker by StoryMaker.

the class MediaProjectManager method checkStorageSpace.

// return space required to pass info up the stack
public double checkStorageSpace() {
    ArrayList<Media> mList = this.mProject.getMediaAsList();
    Long totalBytesRequired = 0l;
    // first check that all of the input images are accessible
    for (Media media : mList) {
        try {
            if (media == null || media.getPath() == null) {
            } else if (!new File(media.getPath()).exists()) {
                throw new java.io.FileNotFoundException();
            } else {
                File currentFile = new File(media.getPath());
                totalBytesRequired += (long) currentFile.length();
            }
        } catch (java.io.FileNotFoundException fnfe) {
            Timber.e(fnfe, "Input image does not exist or is not readable" + ": " + media.getPath());
        }
    }
    // get memory path
    String memoryPath;
    if (mUseInternal) {
        memoryPath = Environment.getDataDirectory().getPath();
    } else {
        memoryPath = Environment.getExternalStorageDirectory().getPath();
    }
    // get memory
    StatFs stat = new StatFs(memoryPath);
    Long totalBytesAvailable = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
    // FIXME we should raise this error via a intent, not a straight toast so it can be handled if the activity is hidden
    if (totalBytesRequired > totalBytesAvailable) {
        double totalMBRequired = totalBytesRequired / (double) (1024 * 1024);
        // can't create toast message here because instances created by renderer have a null value for activity
        return totalMBRequired;
    }
    return 0;
}
Also used : StatFs(android.os.StatFs) Media(org.storymaker.app.model.Media) File(java.io.File)

Example 3 with Media

use of org.storymaker.app.model.Media in project storymaker by StoryMaker.

the class FacebookUploader method start.

// FIXME move the render file checks into base class
@Override
public void start() {
    // TODO Auto-generated constructor stub
    final SiteController controller = SiteController.getSiteController(FacebookSiteController.SITE_KEY, mContext, mHandler, "" + mJob.getId());
    final Project project = mJob.getProject();
    final PublishJob publishJob = mJob.getPublishJob();
    final String path = publishJob.getLastRenderFilePath();
    final Auth auth = (new AuthTable()).getAuthDefault(mContext, FacebookSiteController.SITE_KEY);
    if (Utils.stringNotBlank(path) && (new File(path)).exists()) {
        Handler mainHandler = new Handler(mContext.getMainLooper());
        Runnable myRunnable = new Runnable() {

            // facebook seems to freak out if our service's looper is dead when it tries to send message back
            @Override
            public void run() {
                jobProgress(mJob, 0, mContext.getString(R.string.uploading_to_facebook));
                HashMap<String, String> valueMap = publishJob.getMetadata();
                // need to extract raw photos
                // what happened to STORY_TYPE_PHOTO?
                // TODO: currently checking preferences, will revisit when ui is updated
                SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
                boolean uploadPhotos = sharedPref.getBoolean("pphotoformat", false);
                if ((publishJob.getProject().getStoryType() == Project.STORY_TYPE_ESSAY) && uploadPhotos) {
                    ArrayList<Media> photos = publishJob.getProject().getMediaAsList();
                    String photoString = "";
                    for (Media photo : photos) {
                        photoString = photoString + photo.getPath() + ";";
                    }
                    // drop trailing ;
                    photoString = photoString.substring(0, photoString.length() - 1);
                    valueMap.put(FacebookSiteController.PHOTO_SET_KEY, photoString);
                }
                addValuesToHashmap(valueMap, project.getTitle(), project.getDescription(), path);
                controller.upload(auth.convertToAccountObject(), valueMap);
            }
        };
        mainHandler.post(myRunnable);
    } else {
        Timber.d("Can't upload to facebook, last rendered file doesn't exist.");
        // TODO get this error back to the activity for display
        // FIXME move to strings.xml
        jobFailed(null, ERROR_NO_RENDER_FILE, "Can't upload to facebook, last rendered file doesn't exist.");
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) AuthTable(org.storymaker.app.model.AuthTable) Media(org.storymaker.app.model.Media) Handler(android.os.Handler) SiteController(io.scal.secureshare.controller.SiteController) FacebookSiteController(io.scal.secureshare.controller.FacebookSiteController) PublishJob(org.storymaker.app.model.PublishJob) Project(org.storymaker.app.model.Project) Auth(org.storymaker.app.model.Auth) File(java.io.File)

Example 4 with Media

use of org.storymaker.app.model.Media in project storymaker by StoryMaker.

the class PublishFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    initFragment();
    // purgePublishTables(); // FIXME for debuging, don't purgePublishTables on load!
    int layout = getArguments().getInt("layout");
    mView = inflater.inflate(layout, null);
    String storyPathInstancePath = mActivity.getProject().getTemplatePath();
    if (storyPathInstancePath != null && !storyPathInstancePath.equals("")) {
        File f = new File(storyPathInstancePath);
        // FIXME don't hardcode "en"
        String jsonString = JsonHelper.loadJSON(f.getPath(), getActivity().getApplicationContext(), "en");
        if (jsonString != null) {
            // should not need to insert dependencies to check metadata
            ArrayList<String> referencedFiles = new ArrayList<String>();
            String language = StoryMakerApp.getCurrentLocale().getLanguage();
            mStoryPathInstance = JsonHelper.deserializeStoryPathLibrary(jsonString, f.getAbsolutePath(), referencedFiles, getActivity(), language);
        }
    }
    // mStoryPathInstance = JsonHelper.deserializeStoryPathLibrary(json, storyPathInstancePath, referencedFiles, this, );
    if (layout == R.layout.fragment_complete_story) {
        // FIXME not sure why this check exists
        ProjectInfoFragment infoFrag = ProjectInfoFragment.newInstance(mActivity.getProject().getId(), false, false);
        this.getChildFragmentManager().beginTransaction().replace(R.id.fl_info_container, infoFrag).commit();
        View view = mView.findViewById(R.id.fl_info_container);
        view.findViewById(R.id.fl_info_container).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                launchStoryInfoEditMode();
            }
        });
        // view.setOnTouchListener(new OnTouchListener() {
        // 
        // @Override
        // public boolean onTouch(View v, MotionEvent event) {
        // // TODO Auto-generated method stub
        // return true;
        // }
        // }) ;
        ImageView ivThumb = (ImageView) mView.findViewById(R.id.storyThumb);
        Media[] medias = mActivity.mMPM.mScene.getMediaAsArray();
        if (medias.length > 0) {
            Bitmap bitmap = Media.getThumbnail(mActivity, medias[0], mActivity.mMPM.mProject);
            if (bitmap != null) {
                ivThumb.setImageBitmap(bitmap);
            }
        }
        // FIXME figure out what spec we need to try to fetch for preview... could be audio or video
        mMatchingRenderJob = (new JobTable()).getMatchingFinishedJob(getActivity(), mActivity.mMPM.mProject.getId(), JobTable.TYPE_RENDER, VideoRenderer.SPEC_KEY, mActivity.mMPM.mProject.getUpdatedAt());
        if (mMatchingRenderJob != null) {
            mFileLastExport = new File(mMatchingRenderJob.getResult());
        }
        mProgressText = (TextView) mView.findViewById(R.id.textViewProgress);
        mProgressText.setText("");
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mActivity, R.array.story_sections, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mButtonPlay = (ToggleImageButton) mView.findViewById(R.id.btnPlay);
        mButtonPlay.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                playClicked();
            }
        });
        mButtonUpload = (ToggleImageButton) mView.findViewById(R.id.btnUpload);
        mButtonUpload.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                uploadClicked();
            }
        });
    }
    return mView;
}
Also used : PublishJobTable(org.storymaker.app.model.PublishJobTable) JobTable(org.storymaker.app.model.JobTable) ArrayList(java.util.ArrayList) Media(org.storymaker.app.model.Media) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) DraggableGridView(com.animoto.android.views.DraggableGridView) SuppressLint(android.annotation.SuppressLint) Bitmap(android.graphics.Bitmap) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) File(java.io.File)

Example 5 with Media

use of org.storymaker.app.model.Media in project storymaker by StoryMaker.

the class MediaProjectManager method doExportMedia.

public MediaDesc doExportMedia(File fileExport, boolean doCompress, boolean doOverwrite) throws Exception {
    MediaDesc mMediaDescOut = null;
    Message msg = mHandler.obtainMessage(0);
    msg.getData().putString("status", "cancelled");
    ArrayList<Media> mList = mProject.getMediaAsList();
    ArrayList<MediaDesc> alMediaIn = new ArrayList<MediaDesc>();
    Utils.Proc.killZombieProcs(mContext);
    double storageSpace = checkStorageSpace();
    // if not enough space
    if (storageSpace > 0) {
        // throw exception to pass info up the stack
        throw new Exception(String.format(mContext.getString(R.string.error_storage_space), storageSpace));
    }
    File fileRenderTmpDir = getRenderPath(mContext);
    File fileRenderTmp = new File(fileRenderTmpDir, new Date().getTime() + "");
    fileRenderTmp.mkdirs();
    // for video, render the sequence together
    if (mProject.getStoryType() == Project.STORY_TYPE_VIDEO) {
        int mIdx = 0;
        for (Media media : mList) {
            if (media != null) {
                MediaDesc mediaDesc = new MediaDesc();
                mediaDesc.mimeType = media.getMimeType();
                mediaDesc.path = new File(media.getPath()).getCanonicalPath();
                if (media.getTrimStart() > 0) {
                    mediaDesc.startTime = "" + media.getTrimmedStartTimeFloat() / 1000F;
                    mediaDesc.duration = "" + media.getTrimmedDuration() / 1000F;
                } else if ((media.getTrimEnd() < 99) && media.getTrimEnd() > 0) {
                    mediaDesc.duration = "" + media.getTrimmedDuration() / 1000F;
                }
                mediaDesc.audioVolume = media.getVolume();
                if (doCompress)
                    applyExportSettings(mediaDesc);
                applyExportSettingsResolution(mediaDesc);
                alMediaIn.add(mIdx, mediaDesc);
                mIdx++;
            }
        }
        mMediaDescOut = new MediaDesc();
        if (doCompress)
            applyExportSettings(mMediaDescOut);
        else // this is the default audio codec settings
        {
            mMediaDescOut.audioCodec = "aac";
            mMediaDescOut.audioBitrate = 64;
        }
        applyExportSettingsResolution(mMediaDescOut);
        // override for now
        mMediaDescOut.mimeType = AppConstants.MimeTypes.MP4;
        mMediaDescOut.path = fileExport.getCanonicalPath();
        if ((!fileExport.exists()) || doOverwrite) {
            if (fileExport.exists()) {
                fileExport.delete();
            }
            fileExport.getParentFile().mkdirs();
            // there can be only one renderer now - MP4Stream !!
            MediaVideoExporter mEx = new MediaVideoExporter(mContext, mHandler, alMediaIn, fileRenderTmp, mMediaDescOut);
            // if (audioPath != null)
            for (AudioClip audioClip : mProject.getAudioClipsAsList()) {
                // TODO truncate and pad the font of and set volume on this clip
                String tempPath = audioClip.getPath();
                MediaDesc audioTrack = new MediaDesc();
                audioTrack.path = tempPath;
                // negative time will be padded in export
                audioTrack.startTime = audioClip.getStartTime();
                audioTrack.duration = audioClip.getDuration();
                audioTrack.audioVolume = audioClip.getVolume();
                // TODO put volume in here
                mEx.addAudioTrack(audioTrack);
            }
            mEx.export();
        }
    } else if (mProject.getStoryType() == Project.STORY_TYPE_AUDIO) {
        int mIdx = 0;
        for (Media media : mList) {
            if (media != null) {
                MediaDesc mDesc = new MediaDesc();
                mDesc.mimeType = media.getMimeType();
                mDesc.path = media.getPath();
                if (media.getTrimStart() > 0) {
                    mDesc.startTime = "" + media.getTrimmedStartTimeFloat() / 1000F;
                    mDesc.duration = "" + media.getTrimmedDuration() / 1000F;
                } else if ((media.getTrimEnd() < 99) && media.getTrimEnd() > 0) {
                    mDesc.duration = "" + media.getTrimmedDuration() / 1000F;
                }
                mDesc.audioVolume = media.getVolume();
                if (doCompress)
                    applyExportSettings(mDesc);
                applyExportSettingsResolution(mDesc);
                alMediaIn.add(mIdx++, mDesc);
            }
        }
        mMediaDescOut = new MediaDesc();
        // mOut.mimeType = AppConstants.MimeTypes.OGG;
        // mOut.mimeType = AppConstants.MimeTypes.MP4_AUDIO;
        mMediaDescOut.mimeType = AppConstants.MimeTypes.THREEGPP_AUDIO;
        // if (doCompress)
        applyExportSettingsAudio(mMediaDescOut);
        applyExportSettingsResolution(mMediaDescOut);
        mMediaDescOut.path = fileExport.getCanonicalPath();
        if ((!fileExport.exists()) || doOverwrite) {
            if (fileExport.exists())
                fileExport.delete();
            fileExport.getParentFile().mkdirs();
            MediaAudioExporter mEx = new MediaAudioExporter(mContext, mHandler, alMediaIn, fileRenderTmp, mMediaDescOut);
            mEx.export();
        }
    } else if (mProject.getStoryType() == Project.STORY_TYPE_PHOTO) {
        for (Media media : mList) {
            if (media == null)
                continue;
            MediaDesc mDesc = new MediaDesc();
            mDesc.mimeType = media.getMimeType();
            mDesc.path = media.getPath();
            if (mDesc.path != null) {
                File fileSrc = new File(mDesc.path);
                if (fileSrc.exists()) {
                    fileExport.getParentFile().mkdirs();
                    fileExport.createNewFile();
                    IOUtils.copy(new FileInputStream(fileSrc), new FileOutputStream(fileExport));
                    mMediaDescOut = new MediaDesc();
                    mMediaDescOut.path = fileExport.getCanonicalPath();
                    mMediaDescOut.mimeType = AppConstants.MimeTypes.JPEG;
                    applyExportSettingsResolution(mMediaDescOut);
                    break;
                }
            }
        }
    } else if (mProject.getStoryType() == Project.STORY_TYPE_ESSAY) {
        for (Media media : mList) {
            if (media != null) {
                MediaDesc mDesc = new MediaDesc();
                mDesc.mimeType = media.getMimeType();
                File fileSrc = new File(media.getPath());
                File fileTmp = new File(fileRenderTmp, fileSrc.getName());
                if (!fileTmp.exists()) {
                    fileTmp.getParentFile().mkdirs();
                    fileTmp.createNewFile();
                    IOUtils.copy(new FileInputStream(fileSrc), new FileOutputStream(fileTmp));
                }
                mDesc.path = fileTmp.getCanonicalPath();
                if (doCompress)
                    applyExportSettings(mDesc);
                applyExportSettingsResolution(mDesc);
                alMediaIn.add(mDesc);
            }
        }
        mMediaDescOut = new MediaDesc();
        if (doCompress)
            applyExportSettings(mMediaDescOut);
        applyExportSettingsResolution(mMediaDescOut);
        mMediaDescOut.path = fileExport.getCanonicalPath();
        mMediaDescOut.mimeType = AppConstants.MimeTypes.MP4;
        int slideDuration = Integer.parseInt(mSettings.getString("pslideduration", AppConstants.DEFAULT_SLIDE_DURATION + ""));
        String audioPath = null;
        File fileAudio = new File(getExternalProjectFolder(mProject, mContext), "narration" + mScene.getId() + ".wav");
        if (fileAudio.exists())
            audioPath = fileAudio.getCanonicalPath();
        else {
            // fileAudio = new File(mContext.getExternalFilesDir(null),"narration" + mScene.getId() + ".wav");
            fileAudio = new File(StorageHelper.getActualStorageDirectory(mContext), "narration" + mScene.getId() + ".wav");
            if (fileAudio.exists())
                audioPath = fileAudio.getCanonicalPath();
        }
        if ((!fileExport.exists()) || doOverwrite) {
            if (fileExport.exists())
                fileExport.delete();
            fileExport.getParentFile().mkdirs();
            MediaSlideshowExporter mEx = new MediaSlideshowExporter(mContext, mHandler, alMediaIn, fileRenderTmp, audioPath, slideDuration, mMediaDescOut);
            mEx.export();
        }
    }
    deleteRecursive(fileRenderTmp, true);
    return mMediaDescOut;
}
Also used : Message(android.os.Message) AudioClip(org.storymaker.app.model.AudioClip) MediaSlideshowExporter(org.storymaker.app.media.exporter.MediaSlideshowExporter) Media(org.storymaker.app.model.Media) ArrayList(java.util.ArrayList) MediaDesc(org.ffmpeg.android.MediaDesc) MediaVideoExporter(org.storymaker.app.media.exporter.MediaVideoExporter) IOException(java.io.IOException) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) MediaAudioExporter(org.storymaker.app.media.exporter.MediaAudioExporter)

Aggregations

Media (org.storymaker.app.model.Media)6 File (java.io.File)4 SuppressLint (android.annotation.SuppressLint)2 SharedPreferences (android.content.SharedPreferences)2 Handler (android.os.Handler)2 SiteController (io.scal.secureshare.controller.SiteController)2 ArrayList (java.util.ArrayList)2 Auth (org.storymaker.app.model.Auth)2 AuthTable (org.storymaker.app.model.AuthTable)2 Project (org.storymaker.app.model.Project)2 PublishJob (org.storymaker.app.model.PublishJob)2 Bitmap (android.graphics.Bitmap)1 Message (android.os.Message)1 StatFs (android.os.StatFs)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 DraggableGridView (com.animoto.android.views.DraggableGridView)1 FacebookSiteController (io.scal.secureshare.controller.FacebookSiteController)1