Skip to content

Commit 8f6382f

Browse files
committed
Do not stub out info for invalid files
Originally it was not known if parsing a media file would generally succeed, and as a hedge some sane defaults were given to the user if something went wrong. It seems that parsing media files works well. If an invalid file is provided, the video playback will fail (which is expected), but encoding options are still provided. In this case, the sane defaults are actually more confusing. Removing them, as they are not really needed.
1 parent 3e6888e commit 8f6382f

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

app/src/main/java/protect/videotranscoder/activity/MainActivity.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,28 @@ private void setSpinnerSelection(Spinner spinner, Object value)
10321032
}
10331033
}
10341034

1035+
private void hideAllOptions()
1036+
{
1037+
for(int id : BASIC_SETTINGS_IDS)
1038+
{
1039+
findViewById(id).setVisibility(View.GONE);
1040+
}
1041+
for(int id : VIDEO_SETTINGS_IDS)
1042+
{
1043+
findViewById(id).setVisibility(View.GONE);
1044+
}
1045+
for(int id : AUDIO_SETTINGS_IDS)
1046+
{
1047+
findViewById(id).setVisibility(View.GONE);
1048+
}
1049+
1050+
encodeButton.setVisibility(View.GONE);
1051+
startJumpBack.setVisibility(View.GONE);
1052+
startJumpForward.setVisibility(View.GONE);
1053+
endJumpBack.setVisibility(View.GONE);
1054+
endJumpForward.setVisibility(View.GONE);
1055+
}
1056+
10351057
private void populateOptionDefaults()
10361058
{
10371059
for(int id : BASIC_SETTINGS_IDS)
@@ -1371,26 +1393,25 @@ public void onClick(View v)
13711393
}
13721394
});
13731395

1374-
final File videoFile = new File(path);
1375-
13761396
FFmpegUtil.getMediaDetails(new File(path), new ResultCallbackHandler<MediaInfo>()
13771397
{
13781398
@Override
13791399
public void onResult(MediaInfo result)
13801400
{
1381-
if(result == null)
1382-
{
1383-
Log.d(TAG, "Failed to query media file, filling in defaults");
1384-
// Could not query the file, fill in what we know.
1385-
result = new MediaInfo(videoFile, 0, MediaContainer.MP4, VideoCodec.MPEG4, "640x480",
1386-
800, "25", AudioCodec.MP3,
1387-
44100, 128, 2);
1388-
}
1389-
13901401
videoInfo = result;
1391-
videoInfo.setFileBaseName(overrideBaseName);
13921402

1393-
populateOptionDefaults();
1403+
if(result != null)
1404+
{
1405+
1406+
videoInfo.setFileBaseName(overrideBaseName);
1407+
populateOptionDefaults();
1408+
}
1409+
else
1410+
{
1411+
Toast.makeText(MainActivity.this, R.string.invalidMediaFile, Toast.LENGTH_LONG).show();
1412+
hideAllOptions();
1413+
stopVideoPlayback();
1414+
}
13941415
}
13951416
});
13961417
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<string name="couldNotFindFileSubmsg">could not find input file</string>
3939
<string name="fieldMissingError"><xliff:g id="field_name">%s</xliff:g> missing</string>
4040
<string name="fieldMissingOrInvalidError"><xliff:g id="field_name">%s</xliff:g> missing or invalid</string>
41+
<string name="invalidMediaFile">The selected media file is invalid or not supported</string>
4142

4243
<string name="writePermissionExplanation">This application needs access to storage in order to read and write media files. Without this access, the application cannot transcode.</string>
4344
<string name="permissionRequestAgain">Request again</string>

0 commit comments

Comments
 (0)