Click here to Skip to main content
15,920,687 members
Home / Discussions / Android
   

Android

 
AnswerRe: android studio Pin
Richard MacCutchan3-Jul-17 21:25
mveRichard MacCutchan3-Jul-17 21:25 
SuggestionRe: android studio Pin
David Crow5-Jul-17 4:48
David Crow5-Jul-17 4:48 
QuestionHow do I issue a command that chooses what activity to show in android app? Pin
Gemson Gonzales27-Jun-17 21:24
Gemson Gonzales27-Jun-17 21:24 
AnswerRe: How do I issue a command that chooses what activity to show in android app? Pin
Richard MacCutchan28-Jun-17 8:48
mveRichard MacCutchan28-Jun-17 8:48 
QuestionColor detection in android Pin
Member 1085025318-Jun-17 9:46
Member 1085025318-Jun-17 9:46 
AnswerRe: Color detection in android Pin
Ravi Bhavnani18-Jun-17 11:25
professionalRavi Bhavnani18-Jun-17 11:25 
AnswerRe: Color detection in android Pin
Richard MacCutchan18-Jun-17 23:02
mveRichard MacCutchan18-Jun-17 23:02 
Questionsource code to make online appointment app Pin
Member 1325839413-Jun-17 20:39
Member 1325839413-Jun-17 20:39 
AnswerRe: source code to make online appointment app Pin
Richard MacCutchan13-Jun-17 21:47
mveRichard MacCutchan13-Jun-17 21:47 
AnswerRe: source code to make online appointment app Pin
ZurdoDev28-Jun-17 10:01
professionalZurdoDev28-Jun-17 10:01 
QuestionAndroid jetplayer Pin
Member 132447819-Jun-17 19:24
Member 132447819-Jun-17 19:24 
QuestionRe: Android jetplayer Pin
David Crow11-Jun-17 16:55
David Crow11-Jun-17 16:55 
QuestionShowing text in an android cardboard app (using GvrView) Pin
Member 132057945-Jun-17 22:21
Member 132057945-Jun-17 22:21 
AnswerRe: Showing text in an android cardboard app (using GvrView) Pin
loretta.matos11-Jun-17 21:40
loretta.matos11-Jun-17 21:40 
AnswerRe: Showing text in an android cardboard app (using GvrView) Pin
Arun Ganessh7-Jun-18 1:25
Arun Ganessh7-Jun-18 1:25 
QuestionAttachment To Text Message Pin
C-P-User-331-May-17 16:12
C-P-User-331-May-17 16:12 
QuestionRe: Attachment To Text Message Pin
David Crow3-Jun-17 4:50
David Crow3-Jun-17 4:50 
AnswerRe: Attachment To Text Message Pin
C-P-User-34-Jun-17 5:06
C-P-User-34-Jun-17 5:06 
Questionimport project into android studio Pin
Member 1291906530-May-17 9:59
Member 1291906530-May-17 9:59 
AnswerRe: import project into android studio Pin
Afzaal Ahmad Zeeshan30-May-17 11:45
professionalAfzaal Ahmad Zeeshan30-May-17 11:45 
AnswerRe: import project into android studio Pin
David Crow30-May-17 12:54
David Crow30-May-17 12:54 
Questionitexg Pin
Member 1322987429-May-17 16:17
Member 1322987429-May-17 16:17 
AnswerRe: itexg Pin
Richard MacCutchan29-May-17 20:55
mveRichard MacCutchan29-May-17 20:55 
QuestionRe: itexg Pin
David Crow30-May-17 5:54
David Crow30-May-17 5:54 
QuestionMediaExtractor.setDataSource works or doesn't based on Android OS version Pin
JudyL_MD28-May-17 8:47
JudyL_MD28-May-17 8:47 
It's been a while since I've participated on CP, and I'm back with a doozy

I'm having a problem with MediaExtractor and using a MemoryFile as the data source. In the real world, this media viewer is part of a larger app that supplies a chunk of bytes that contains a complete MP4 video. To eliminate all the other stuff, I have created a little demo app that only contains the viewer and a test MemoryFile. Please note that not using a MemoryFile, i.e. saving the video data to storage and playing from there, is not an option.

First, the code. I create the MemoryFile in the test app's MainActivity.onCreate
// these lines are only in the test app
InputStream inS = getResources ().getAssets ().open ("testmp4.mp4");

int length = inS.available ();
byte[] data = new byte[length];
inS.read (data);
inS.close ();

// in the real world, the other stuff gives me a byte[] array and my code starts here
m_memFile = new MemoryFile (null, length);
m_memFile.writeBytes (data, 0, 0, length);

Method getFD = MemoryFile.class.getMethod ("getFileDescriptor");
m_memFileFD = (FileDescriptor) getFD.invoke (m_memFile);

This is in the MainActivity's Play button click listener:
if (m_player == null)
{
    m_player = new MyPlayer (MainActivity.this.m_events, MainActivity.this.m_memFileFD, MainActivity.this.m_memFile.length (), (SurfaceView) findViewById (R.id.viewerMediaVideo));
}
m_player.play ();

The video player is in the class MyPlayer that extends Runnable:
protected MediaExtractor m_extractor  = null;
protected PlayerStates   m_state     = PlayerStates.STOPPED;
private SurfaceHolder    m_surface     = null;
protected FileDescriptor m_memFileFD  = null;
protected long           m_memFileLen = 0;

public MyPlayer (PlayerEvents ev, FileDescriptor fd, long len, SurfaceView s)
{
    m_events = ev;
    m_memFileFD = fd;
    m_memFileLen = len;
    m_surface = s.getHolder ();
}

public void play ()
{
    if (m_state == PlayerStates.STOPPED)
    {
        m_stop = false;
        new Thread (this).start ();
    }
    ...
}

public void run ()
{
    android.os.Process.setThreadPriority (Process.THREAD_PRIORITY_URGENT_AUDIO);

    m_extractor = new MediaExtractor ();
    try
    {
        m_extractor.setDataSource (m_memFileFD, 0, m_memFileLen);
    }
    catch (final Exception excp)
    {
        m_extractor.release ();
        m_extractor = null;

        m_handler.post (new Runnable (){public void run ()
                       {m_events.onError ("can't create extractor: " + excp.getMessage ()); } });
        return;
    }
    ....
}

Now for the problem. I have tested the same APK on different devices, both actual physical phones and emulators and the results are:

S5 with 4.4.2 / API:19 emulator --> works
M9 with 5.0.2 / API:21 emulator / API:22 emulator --> works
Nexus6 with 6.0 / API:23 emulator --> works
S7 with 6.0.1 / (no emulator for this point release) --> fails
Nexus6 with 7.0 / API:24 emulator --> fails

works means the video plays correctly
fails means I get the error "can't create extractor: Failed to instantiate extractor". This is the catch at the very beginning of the player's run method

6.0.1 logcat shows thirteen lines like (only varying between the digit 0 and 4):
FileSource: seek to 0 failed
7.0 / API:24 emulator logcat contains a single line:
FileSource: offset/length adjusted from 0/547251 to 0/0

I've tried two versions of the app on the physical devices. One has a minimumSDK set to 19 and the targetSDK / compileSDK / build tools are version 21. The second version has minSDK 19 and the rest 23. The version running on the emulators has minSDK19, targetSDK 23, and compileSDK/ buildTools 25 -- the latest that I just downloaded yesterday. All three different builds of the same code fail in the same pattern based on OS version.

This points me to a change between OS versions 6.0 and 6.0.1 causing the issue. However, I've done some poking into the sources available on the net and don't see anything suspicious.

Any ideas? Do I need to go report a bug to Google?
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.