Click here to Skip to main content
15,884,537 members
Home / Discussions / Android
   

Android

 
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

AnswerRe: MediaExtractor.setDataSource works or doesn't based on Android OS version Pin
JudyL_MD6-Nov-17 4:41
JudyL_MD6-Nov-17 4:41 
QuestionAndroid chat application message notification receive issue Pin
Pavlex426-May-17 20:46
Pavlex426-May-17 20:46 
SuggestionRe: Android chat application message notification receive issue Pin
Richard MacCutchan26-May-17 21:57
mveRichard MacCutchan26-May-17 21:57 
QuestionNeural Network Algorithms Pin
Member 1320852321-May-17 20:30
Member 1320852321-May-17 20:30 
AnswerRe: Neural Network Algorithms Pin
David Crow22-May-17 3:28
David Crow22-May-17 3:28 
GeneralRe: Neural Network Algorithms Pin
Member 1320852323-May-17 2:32
Member 1320852323-May-17 2:32 
AnswerRe: Neural Network Algorithms Pin
Richard MacCutchan22-May-17 6:48
mveRichard MacCutchan22-May-17 6:48 
Questionhow can I make my android app location aware? Pin
Member 1320194920-May-17 8:38
Member 1320194920-May-17 8:38 
AnswerRe: how can I make my android app location aware? Pin
Afzaal Ahmad Zeeshan20-May-17 9:47
professionalAfzaal Ahmad Zeeshan20-May-17 9:47 
AnswerRe: how can I make my android app location aware? Pin
David Crow20-May-17 10:16
David Crow20-May-17 10:16 
QuestionAndroid connect to MS SQL Server Pin
Member 1190014018-May-17 18:31
Member 1190014018-May-17 18:31 
AnswerRe: Android connect to MS SQL Server Pin
Peter_in_278018-May-17 18:53
professionalPeter_in_278018-May-17 18:53 
GeneralRe: Android connect to MS SQL Server Pin
Member 1190014018-May-17 19:38
Member 1190014018-May-17 19:38 
GeneralRe: Android connect to MS SQL Server Pin
Peter_in_278018-May-17 20:56
professionalPeter_in_278018-May-17 20:56 
AnswerRe: Android connect to MS SQL Server Pin
Richard MacCutchan18-May-17 21:48
mveRichard MacCutchan18-May-17 21:48 
GeneralRe: Android connect to MS SQL Server Pin
Member 1190014018-May-17 21:56
Member 1190014018-May-17 21:56 
GeneralRe: Android connect to MS SQL Server Pin
Richard MacCutchan18-May-17 22:12
mveRichard MacCutchan18-May-17 22:12 

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.