SlideShare a Scribd company logo
1 of 8
Download to read offline
Flow of events during Media Player Creation in
Android
Somenath Mukhopadhyay
som.mukhopadhyay@gmail.com
The flow of events of the Android media player is complex. This document will serve as a
hand-holding for code walkthrough of the Android multimedia framework for the Android lovers.
To start with, let me give you the call stack of the media player framework in Android. This has
been depicted as in the following diagram.

Now lets come to the fact findings. There are two sides of the Android Media Framework. What we
as an user see is the Java interface which is called the Mediaplayer.java. However, this java
interface interacts with a native mediaplayer object through Java Native Interface (JNI)
mechanism. This interaction is done through the functionalities defined in
Android_media_Mediaplayer.cpp. In this file the framework engineers have kept all the
necessary JNI functions.
Now when we are about to start the MediaPlayer, the JNI function that is called is the
private native final void native_setup.
This function is actually responsible for creating a C++ mediaplayer object in the native side and
storing it as an opaque reference in the Java client side. So when we interact with the client side
Java mediaplayer object, we internally interact with this native C++ object.
The JNI layer actually delegates its task to a Mediaplayer object. The functionalities of this C++
class are defined in the file Mediaplayer.cpp.
Now the next step is that we set a data source in the Java side using the function setDataSource
function in which the URI of the data source is passed. This in turn calls the native function
android_media_MediaPlayer_setDataSource(JNIEnv *env, jobject thiz, jstring path)
In the native source, this function is defined as
adodmdaMdalyrstaaoreJIn *n,jbetti,jtigpt)
nri_ei_eiPae_eDtSuc(NEv ev ojc hz srn ah
{
s < e i P a e >m =g t e i P a e ( n , t i )
pMdalyr  p   eMdalyrev hz;
i  ( p =  N L  ) {
f m = UL
jihoEcpinev "aaln/leaSaexeto" NL)
nTrwxeto(n, jv/agIlglttEcpin, UL;
rtr;
eun
}
i  ( a h =  N L ) {
f pt = UL
jihoEcpinev "aaln/leaAgmnEcpin,NL)
nTrwxeto(n, jv/agIlglruetxeto" UL;
rtr;
eun
}
c n tc a  * a h t =e v > e S r n U F h r ( a h N L )
os  hr ptSr   n-GttigTCaspt, UL;
i  ( a h t =  N L ) { / O t o m m r
f ptSr = UL
/ u f eoy
jihoEcpinev "aaln/utmEcpin,"u o mmr";
nTrwxeto(n, jv/agRniexeto" Ot f eoy)
rtr;
eun
}
LG(staaore pt %" ptSr;
OV"eDtSuc: ah s, aht)
s a u _  o S a u =m - s t a a o r e p t S r ;
ttst ptts   p>eDtSuc(aht)
/ Mk sr ta lclrfi rlae bfr aptnilecpin
/ ae ue ht oa e s eesd eoe
oeta xeto
ev>eesSrnUFhr(ah ptSr;
n-RlaetigTCaspt, aht)
poesmdapae_al ev ti,oSau,"aai/Oxeto" "eDtSuc
rcs_ei_lyrcl( n, hz ptts jv/oIEcpin, staaore
f i e .  )
ald" ;
}
Look at the line:
status_t opStatus = mp->setDataSource(pathStr);
This function is defined as
s a u _  M d a l y r : e D t S u c ( o s  c a  * r )
ttst eiPae:staaorecnt hr ul
{
LG(staaore%),ul;
OV"eDtSuc(s" r)
s a u _  e r =B D V L E
ttst r   A_AU;
i  ( r !  N L ) {
f ul = UL
c n ts < M d a l y r e v c >  s r i e g t e i P a e S r i e ) ;
os  pIeiPaeSrie& evc(eMdalyrevc()
i  ( e v c !  0 {
f srie = )
s < M d a l y r  p a e ( e v c - c e t ( e p d ) t i , u l )
pIeiPae> lyrsrie>raegti(, hs r);
e r =s t a a o r e p a e )
r   eDtSuc(lyr;
}
}
r t r  e r
eun r;
}
Look at the line :
sp<IMediaPlayer> player(service->create(getpid(), this, url));
It actually takes the help of the IMediaPlayerservice layer and calls the create function on this. This
function can be found in basemedialibmediaIMediaPlayerService.cpp file.
The create function of the MediaPlayerService looks like the following. It can be found at
basemedialibmediaplayerserviceMediaPlayerService.cpp.

sp<IMediaPlayer>
MediaPlayerService::create(pid_t pid, const
s < M d a l y r  M d a l y r e v c : c e t ( i _  p d c n ts < M d a l y r l e t &
pIeiPae> eiPaeSrie:raepdt i, os  pIeiPaeCin>
c i n , c n tc a *u l
let os  hr  r)
{
i t 2 tc n I =a d o d a o i _ n ( m e t o n d ;
n3_  ond   nri_tmcic&NxCnI)
s < l e t  c =n wC i n ( h s p d c n I , c i n )
pCin>
  e  letti, i, ond let;
LG(Cet nwcin(d fo pd%,ul%,cnI=d,cnI,pd ul cnI)
OV"rae e let%) rm i d r=s ond%" ond i, r, ond;
i  ( O E R R !  c > e D t S u c ( r )
f N_RO = -staaoreul)
{
ccer)
.la(;
r t r  c
eun ;
}
w < l e t  w =c
pCin>
  ;
Mtx:uooklc(Lc)
ue:Atlc okmok;
mlet.d()
Cinsadw;
r t r  c
eun ;
}

Look at the line :

sp<Client> c = new Client(this, pid, connId, client)
The client constructor is as the following:
s < M d a l y r  M d a l y r e v c : c e t ( i _  p d c n ts < M d a l y r l e t &
pIeiPae> eiPaeSrie:raepdt i, os  pIeiPaeCin>
c i n , c n tc a *u l
let os  hr  r)
{
i t 2 tc n I =a d o d a o i _ n ( m e t o n d ;
n3_  ond   nri_tmcic&NxCnI)
s < l e t  c =n wC i n ( h s p d c n I , c i n )
pCin>
  e  letti, i, ond let;
LG(Cet nwcin(d fo pd%,ul%,cnI=d,cnI,pd ul cnI)
OV"rae e let%) rm i d r=s ond%" ond i, r, ond;
i  ( O E R R !  c > e D t S u c ( r )
f N_RO = -staaoreul)
{
ccer)
.la(;
r t r  c
eun ;
}
w < l e t  w =c
pCin>
  ;
Mtx:uooklc(Lc)
ue:Atlc okmok;
mlet.d()
Cinsadw;
r t r  c
eun ;
}
Now look at the following line (line number 6) of sp<IMediaPlayer>
MediaPlayerService::create(pid_t pid, const sp<IMediaPlayerClient>& client, const char* url)
if (NO_ERROR != c->setDataSource(url))
So we are basically calling the setDataSource on the Client.
This function is like the following:
s a u _  M d a l y r e v c : C i n : s t a a o r e c n tc a  * r )
ttst eiPaeSrie:let:eDtSuc(os  hr ul
{
LG(staaore%),ul;
OV"eDtSuc(s" r)
i  ( r =  N L )
f ul = UL
r t r  U K O N E R R
eun NNW_RO;
i  ( t n m ( r , " o t n : / , 1 ) =  0 {
f srcpul cnet/" 0 = )
/ gtafldsrpo frtecnetUiad
/ e
ieecitr o h otn r n
/ ps i t testaaoref)mto
/ as t o h eDtSuc(d ehd
Srn1 ul6ul;
tig6 r1(r)
i tf =a d o d : p n o t n P o i e F l ( r 1 )
n  d   nri:oeCnetrvdrieul6;
i  ( d <0
f f   )
{
LG(Cud' oe f fr%" ul;
OE"olnt pn d o s, r)
r t r  U K O N E R R
eun NNW_RO;
}
staaoref,0 07ffffL) / ti st mtts
eDtSuc(d , xfffffL; / hs es Sau
coef)
ls(d;
r t r  m t t s
eun Sau;
} e s  {
le
p a e _ y e p a e T p =g t l y r y e u l ;
lyrtp lyrye   ePaeTp(r)
LG(pae tp =%" paeTp)
OV"lyr ye
d, lyrye;
/ cet tergttp o pae
/ rae h ih ye f lyr
s < e i P a e B s >p =c e t P a e ( l y r y e ;
pMdalyrae 
  raelyrpaeTp)
i  ( =  N L ) r t r  N _ N T
f p = UL eun OII;
i  ( p > a d a e u p t ) {
f !-hrwrOtu()
m u i O t u =n wA d o u p t )
Adoupt   e  uiOtu(;
sai_atMdalyrnefc*(.e()>eAdoikmuiOtu)
ttccs<eiPaeItrae>pgt)-stuiSn(Adoupt;
}
/ nwstdt suc
/ o e aa ore
LG( staaore)
OV" eDtSuc";
m t t s =p > e D t S u c ( r )
Sau   -staaoreul;
i  ( S a u =  N _ R O ) m l y r =p
f mtts = OERR Pae   ;
r t r  m t t s
eun Sau;
}
}
From the above code snippet it becomes clear that either we do
i  ( t n m ( r , " o t n : / , 1 ) =  0 {
f srcpul cnet/" 0 = )
/ gtafldsrpo frtecnetUiad
/ e
ieecitr o h otn r n
/ ps i t testaaoref)mto
/ as t o h eDtSuc(d ehd
Srn1 ul6ul;
tig6 r1(r)
i tf =a d o d : p n o t n P o i e F l ( r 1 )
n  d   nri:oeCnetrvdrieul6;
i  ( d <0
f f   )
{
LG(Cud' oe f fr%" ul;
OE"olnt pn d o s, r)
r t r  U K O N E R R
eun NNW_RO;
}
staaoref,0 07ffffL) / ti st mtts
eDtSuc(d , xfffffL; / hs es Sau
coef)
ls(d;
r t r  m t t s
eun Sau;

●
●

or

we do the following:

e s  {
le
p a e _ y e p a e T p =g t l y r y e u l ; / h r i e t a t t e P a e T p f o
lyrtp lyrye   ePaeTp(r) /ee t xrcs h lyr ye rm
teUL
h R.
LG(pae tp =%" paeTp)
OV"lyr ye
d, lyrye;
/ cet tergttp o pae
/ rae h ih ye f lyr
s < e i P a e B s >p =c e t P a e ( l y r y e ;
pMdalyrae 
  raelyrpaeTp)
.......
.......
.......
.......
I t e f r t c s  t e s t a a o r e ( i e 1 ) f n t o l o s l k t e f l o i g
n h is ae h eDtSuc ln 2 ucin ok ie h olwn:
s a u _  M d a l y r e v c : C i n : s t a a o r e i tf , i t 4 to f e , i t 4 tl n t )
ttst eiPaeSrie:let:eDtSuc(n  d n6_  fst n6_  egh
{
LG(staaoref=d ofe=ld lnt=ld,f,ofe,lnt)
OV"eDtSuc d%, fst%l, egh%l" d fst egh;
s r c  s a s ;
tut tt b
i tr t =f t t f , & b ;
n  e   sa(d s)
i  ( e !  0 {
f rt = )
LG(ftt%)fie:%,%" f,rt srro(rn);
OE"sa(d ald d s, d e, terrero)
r t r  U K O N E R R
eun NNW_RO;
}
LG(s_e =%l" s.tdv;
OV"tdv
lu, bs_e)
LG(s_oe=%" s.tmd)
OV"tmd
u, bs_oe;
LG(s_i =%u,s.tud;
OV"tud
l" bs_i)
LG(s_i =%u,s.tgd;
OV"tgd
l" bs_i)
LG(s_ie=%l" s.tsz)
OV"tsz
lu, bs_ie;
i  ( f s t >  s . t s z ) {
f ofe = bs_ie
LG(ofe err)
OE"fst ro";
:coef)
:ls(d;
r t r  U K O N E R R
eun NNW_RO;
}
i  ( f s t +l n t >s . t s z ) {
f ofe   egh   bs_ie
l n t =s . t s z -o f e ;
egh   bs_ie   fst
LG(cluae lnt =%l" lnt)
OV"acltd egh
ld, egh;
}
p a e _ y e p a e T p =g t l y r y e f , o f e , l n t ) / h r i g t t e f l t p
lyrtp lyrye   ePaeTp(d fst egh; /ee t es h ie ye
fo teFl dsrpo
rm h ie ecitr
LG(pae tp =%" paeTp)
OV"lyr ye
d, lyrye;
/ cet tergttp o pae
/ rae h ih ye f lyr
s < e i P a e B s >p =c e t P a e ( l y r y e ;
pMdalyrae 
  raelyrpaeTp)
i  ( =  N L ) r t r  N _ N T
f p = UL eun OII;
i  ( p > a d a e u p t ) {
f !-hrwrOtu()
m u i O t u =n wA d o u p t )
Adoupt   e  uiOtu(;
sai_atMdalyrnefc*(.e()>eAdoikmuiOtu)
ttccs<eiPaeItrae>pgt)-stuiSn(Adoupt;
}
/ nwstdt suc
/ o e aa ore
m t t s =p > e D t S u c ( d o f e , l n t )
Sau   -staaoref, fst egh;
i  ( S a u =  N _ R O ) m l y r =p
f mtts = OERR Pae   ;
r t r  m t t s
eun Sau;
}
Look at the line :
sp<MediaPlayerBase> p = createPlayer(playerType). It becomes clear that we create the
player here.
The sp<MediaPlayerBase> p = createPlayer (playerType) actually creates the right player.
In the second case (the else part) we call sp<MediaPlayerBase> p = createPlayer(playerType)
at line 6. We extract the file type from the URL. This helps us in creating the right player object.
The createPlayer function looks like the following:
s < e i P a e B s >M d a l y r e v c : C i n : c e t P a e ( l y r t p p a e T p )
pMdalyrae  eiPaeSrie:let:raelyrpae_ye lyrye
{
/ dtriei w hv tergtpae tp
/ eemn f e ae h ih lyr ye
s < e i P a e B s >p =m l y r
pMdalyrae 
  Pae;
i  ( p !  N L ) &  ( - p a e T p ( !  p a e T p ) {
f ( = UL & p>lyrye) = lyrye)
LG(dlt pae";
OV"eee lyr)
pcer)
.la(;
}
i  ( =  N L ) {
f p = UL
p =a d o d : r a e l y r p a e T p , t i , n t f )
  nri:cetPae(lyrye hs oiy;
}
r t r  p
eun ;
}
Hence it actually delegates the task to p = android::createPlayer(playerType, this, notify);
The above function is as follows;
s a i  s < e i P a e B s >c e t P a e ( l y r t p p a e T p , v i *c o i ,
ttc pMdalyrae  raelyrpae_ye lyrye od  oke
ntf_alakfntfFn)
oiyclbc_ oiyuc
{
s < e i P a e B s >p
pMdalyrae  ;
s i c  ( l y r y e {
wth paeTp)
#fdfN_PNOE
ine OOECR
c s  P _ L Y R
ae VPAE:
LG( cet PPae";
OV" rae Vlyr)
p =n wP P a e ( ;
  e  Vlyr)
bek
ra;
#ni
edf
c s  S N V X P A E :
ae OIO_LYR
LG( cet MdFl";
OV" rae iiie)
p =n wM d F l ( ;
  e  iiie)
bek
ra;
c s  V R I _ L Y R
ae OBSPAE:
LG( cet VriPae";
OV" rae obslyr)
p =n wV r i P a e ( ;
  e  obslyr)
bek
ra;
}
i  ( !  N L ) {
f p = UL
i  ( - i i C e k ) =  N _ R O ) {
f p>nthc( = OERR
p>eNtfClbc(oke ntfFn)
-stoiyalakcoi, oiyuc;
} e s  {
le
pcer)
.la(;
}
}
i  ( =  N L ) {
f p = UL
LG(Fie t cet pae ojc";
OE"ald o rae lyr bet)
}
r t r  p
eun ;
}
Thus we find that the right player is created through the parameterized factory function
createPlayer.
i hope this explains how the right mediaplayer is created from the Uri passed in the Java client
side interface of the Mediaplyer.

More Related Content

What's hot

Drupal 8 in action, the route to the method
Drupal 8 in action, the route to the methodDrupal 8 in action, the route to the method
Drupal 8 in action, the route to the method
juanolalla
 
An integrated-approach-to-intermediate-japanese
An integrated-approach-to-intermediate-japaneseAn integrated-approach-to-intermediate-japanese
An integrated-approach-to-intermediate-japanese
Ito Ree
 
Islamic Lessons for children(বইঃ ইসলামী বাল্য শিক্ষা)
Islamic Lessons for children(বইঃ ইসলামী বাল্য শিক্ষা)Islamic Lessons for children(বইঃ ইসলামী বাল্য শিক্ষা)
Islamic Lessons for children(বইঃ ইসলামী বাল্য শিক্ষা)
Self
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
Edorian
 

What's hot (20)

Create Custom Post Type Plugin
Create Custom Post Type PluginCreate Custom Post Type Plugin
Create Custom Post Type Plugin
 
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
 
Porivnyalna tablicya do proektu zakonu pro vnesennya zmin do deyakih zakonoda...
Porivnyalna tablicya do proektu zakonu pro vnesennya zmin do deyakih zakonoda...Porivnyalna tablicya do proektu zakonu pro vnesennya zmin do deyakih zakonoda...
Porivnyalna tablicya do proektu zakonu pro vnesennya zmin do deyakih zakonoda...
 
Drupal 8 in action, the route to the method
Drupal 8 in action, the route to the methodDrupal 8 in action, the route to the method
Drupal 8 in action, the route to the method
 
Climbing the Abstract Syntax Tree (phpDay 2017)
Climbing the Abstract Syntax Tree (phpDay 2017)Climbing the Abstract Syntax Tree (phpDay 2017)
Climbing the Abstract Syntax Tree (phpDay 2017)
 
Interpret this... (PHPem 2016)
Interpret this... (PHPem 2016)Interpret this... (PHPem 2016)
Interpret this... (PHPem 2016)
 
An integrated-approach-to-intermediate-japanese
An integrated-approach-to-intermediate-japaneseAn integrated-approach-to-intermediate-japanese
An integrated-approach-to-intermediate-japanese
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)
 
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
 
JavaScript pitfalls
JavaScript pitfallsJavaScript pitfalls
JavaScript pitfalls
 
Theme Development and Customization
Theme Development and CustomizationTheme Development and Customization
Theme Development and Customization
 
Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
Islamic Lessons for children(বইঃ ইসলামী বাল্য শিক্ষা)
Islamic Lessons for children(বইঃ ইসলামী বাল্য শিক্ষা)Islamic Lessons for children(বইঃ ইসলামী বাল্য শিক্ষা)
Islamic Lessons for children(বইঃ ইসলামী বাল্য শিক্ষা)
 
The Ring programming language version 1.4 book - Part 15 of 30
The Ring programming language version 1.4 book - Part 15 of 30The Ring programming language version 1.4 book - Part 15 of 30
The Ring programming language version 1.4 book - Part 15 of 30
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
Javascript: The Important Bits
Javascript: The Important BitsJavascript: The Important Bits
Javascript: The Important Bits
 
Solutions manual for operations research an introduction 10th edition by taha...
Solutions manual for operations research an introduction 10th edition by taha...Solutions manual for operations research an introduction 10th edition by taha...
Solutions manual for operations research an introduction 10th edition by taha...
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 

Similar to Flow of events during Media Player creation in Android

Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
Michael Peacock
 

Similar to Flow of events during Media Player creation in Android (20)

Architecting Android Apps: Marko Gargenta
Architecting Android Apps: Marko GargentaArchitecting Android Apps: Marko Gargenta
Architecting Android Apps: Marko Gargenta
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
 
SecureSocial - Authentication for Play Framework
SecureSocial - Authentication for Play FrameworkSecureSocial - Authentication for Play Framework
SecureSocial - Authentication for Play Framework
 
Using Phing for Fun and Profit
Using Phing for Fun and ProfitUsing Phing for Fun and Profit
Using Phing for Fun and Profit
 
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
 
Social Network Analysis With R
Social Network Analysis With RSocial Network Analysis With R
Social Network Analysis With R
 
Beginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleBeginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at Google
 
Angular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental FeatureAngular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental Feature
 
Java 8 - project lambda
Java 8 - project lambdaJava 8 - project lambda
Java 8 - project lambda
 
WordPress in 30 minutes
WordPress in 30 minutesWordPress in 30 minutes
WordPress in 30 minutes
 
TensorFlow 2: New Era of Developing Deep Learning Models
TensorFlow 2: New Era of Developing Deep Learning ModelsTensorFlow 2: New Era of Developing Deep Learning Models
TensorFlow 2: New Era of Developing Deep Learning Models
 
One page app with AngularJS
One page app with AngularJSOne page app with AngularJS
One page app with AngularJS
 
GraphQL Relay Introduction
GraphQL Relay IntroductionGraphQL Relay Introduction
GraphQL Relay Introduction
 
Testing TYPO3 Applications
Testing TYPO3 ApplicationsTesting TYPO3 Applications
Testing TYPO3 Applications
 
Advanced QUnit - Front-End JavaScript Unit Testing
Advanced QUnit - Front-End JavaScript Unit TestingAdvanced QUnit - Front-End JavaScript Unit Testing
Advanced QUnit - Front-End JavaScript Unit Testing
 
Breathe life into your designer!
Breathe life into your designer!Breathe life into your designer!
Breathe life into your designer!
 
Marksheets of RKDwivedi
Marksheets of RKDwivediMarksheets of RKDwivedi
Marksheets of RKDwivedi
 
Tercera parte parte del Cuaderno de Ingles
Tercera parte parte del Cuaderno de InglesTercera parte parte del Cuaderno de Ingles
Tercera parte parte del Cuaderno de Ingles
 
Minicurso Android
Minicurso AndroidMinicurso Android
Minicurso Android
 
Starting out with Ember.js
Starting out with Ember.jsStarting out with Ember.js
Starting out with Ember.js
 

More from Somenath Mukhopadhyay

More from Somenath Mukhopadhyay (20)

Significance of private inheritance in C++...
Significance of private inheritance in C++...Significance of private inheritance in C++...
Significance of private inheritance in C++...
 
Arranging the words of a text lexicographically trie
Arranging the words of a text lexicographically   trieArranging the words of a text lexicographically   trie
Arranging the words of a text lexicographically trie
 
Generic asynchronous HTTP utility for android
Generic asynchronous HTTP utility for androidGeneric asynchronous HTTP utility for android
Generic asynchronous HTTP utility for android
 
Copy on write
Copy on writeCopy on write
Copy on write
 
Java concurrency model - The Future Task
Java concurrency model - The Future TaskJava concurrency model - The Future Task
Java concurrency model - The Future Task
 
Memory layout in C++ vis a-vis polymorphism and padding bits
Memory layout in C++ vis a-vis polymorphism and padding bitsMemory layout in C++ vis a-vis polymorphism and padding bits
Memory layout in C++ vis a-vis polymorphism and padding bits
 
Developing an Android REST client to determine POI using asynctask and integr...
Developing an Android REST client to determine POI using asynctask and integr...Developing an Android REST client to determine POI using asynctask and integr...
Developing an Android REST client to determine POI using asynctask and integr...
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Uml training
Uml trainingUml training
Uml training
 
How to create your own background for google docs
How to create your own background for google docsHow to create your own background for google docs
How to create your own background for google docs
 
The Designing of a Software System from scratch with the help of OOAD & UML -...
The Designing of a Software System from scratch with the help of OOAD & UML -...The Designing of a Software System from scratch with the help of OOAD & UML -...
The Designing of a Software System from scratch with the help of OOAD & UML -...
 
Structural Relationship between Content Resolver and Content Provider of Andr...
Structural Relationship between Content Resolver and Content Provider of Andr...Structural Relationship between Content Resolver and Content Provider of Andr...
Structural Relationship between Content Resolver and Content Provider of Andr...
 
Implementation of a state machine for a longrunning background task in androi...
Implementation of a state machine for a longrunning background task in androi...Implementation of a state machine for a longrunning background task in androi...
Implementation of a state machine for a longrunning background task in androi...
 
Tackling circular dependency in Java
Tackling circular dependency in JavaTackling circular dependency in Java
Tackling circular dependency in Java
 
Implementation of composite design pattern in android view and widgets
Implementation of composite design pattern in android view and widgetsImplementation of composite design pattern in android view and widgets
Implementation of composite design pattern in android view and widgets
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ ConstructorException Handling in the C++ Constructor
Exception Handling in the C++ Constructor
 
Active object of Symbian in the lights of client server architecture
Active object of Symbian in the lights of client server architectureActive object of Symbian in the lights of client server architecture
Active object of Symbian in the lights of client server architecture
 
Android services internals
Android services internalsAndroid services internals
Android services internals
 
Android Asynctask Internals vis-a-vis half-sync half-async design pattern
Android Asynctask Internals vis-a-vis half-sync half-async design patternAndroid Asynctask Internals vis-a-vis half-sync half-async design pattern
Android Asynctask Internals vis-a-vis half-sync half-async design pattern
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Flow of events during Media Player creation in Android

  • 1. Flow of events during Media Player Creation in Android Somenath Mukhopadhyay som.mukhopadhyay@gmail.com The flow of events of the Android media player is complex. This document will serve as a hand-holding for code walkthrough of the Android multimedia framework for the Android lovers. To start with, let me give you the call stack of the media player framework in Android. This has been depicted as in the following diagram. Now lets come to the fact findings. There are two sides of the Android Media Framework. What we as an user see is the Java interface which is called the Mediaplayer.java. However, this java interface interacts with a native mediaplayer object through Java Native Interface (JNI) mechanism. This interaction is done through the functionalities defined in Android_media_Mediaplayer.cpp. In this file the framework engineers have kept all the necessary JNI functions. Now when we are about to start the MediaPlayer, the JNI function that is called is the private native final void native_setup. This function is actually responsible for creating a C++ mediaplayer object in the native side and storing it as an opaque reference in the Java client side. So when we interact with the client side Java mediaplayer object, we internally interact with this native C++ object.
  • 2. The JNI layer actually delegates its task to a Mediaplayer object. The functionalities of this C++ class are defined in the file Mediaplayer.cpp. Now the next step is that we set a data source in the Java side using the function setDataSource function in which the URI of the data source is passed. This in turn calls the native function android_media_MediaPlayer_setDataSource(JNIEnv *env, jobject thiz, jstring path) In the native source, this function is defined as adodmdaMdalyrstaaoreJIn *n,jbetti,jtigpt) nri_ei_eiPae_eDtSuc(NEv ev ojc hz srn ah { s < e i P a e >m =g t e i P a e ( n , t i ) pMdalyr  p   eMdalyrev hz; i  ( p =  N L  ) { f m = UL jihoEcpinev "aaln/leaSaexeto" NL) nTrwxeto(n, jv/agIlglttEcpin, UL; rtr; eun } i  ( a h =  N L ) { f pt = UL jihoEcpinev "aaln/leaAgmnEcpin,NL) nTrwxeto(n, jv/agIlglruetxeto" UL; rtr; eun } c n tc a  * a h t =e v > e S r n U F h r ( a h N L ) os  hr ptSr   n-GttigTCaspt, UL; i  ( a h t =  N L ) { / O t o m m r f ptSr = UL / u f eoy jihoEcpinev "aaln/utmEcpin,"u o mmr"; nTrwxeto(n, jv/agRniexeto" Ot f eoy) rtr; eun } LG(staaore pt %" ptSr; OV"eDtSuc: ah s, aht) s a u _  o S a u =m - s t a a o r e p t S r ; ttst ptts   p>eDtSuc(aht) / Mk sr ta lclrfi rlae bfr aptnilecpin / ae ue ht oa e s eesd eoe oeta xeto ev>eesSrnUFhr(ah ptSr; n-RlaetigTCaspt, aht) poesmdapae_al ev ti,oSau,"aai/Oxeto" "eDtSuc rcs_ei_lyrcl( n, hz ptts jv/oIEcpin, staaore f i e .  ) ald" ; } Look at the line: status_t opStatus = mp->setDataSource(pathStr); This function is defined as s a u _  M d a l y r : e D t S u c ( o s  c a  * r ) ttst eiPae:staaorecnt hr ul { LG(staaore%),ul; OV"eDtSuc(s" r) s a u _  e r =B D V L E ttst r   A_AU; i  ( r !  N L ) { f ul = UL c n ts < M d a l y r e v c >  s r i e g t e i P a e S r i e ) ; os  pIeiPaeSrie& evc(eMdalyrevc() i  ( e v c !  0 { f srie = )
  • 3. s < M d a l y r  p a e ( e v c - c e t ( e p d ) t i , u l ) pIeiPae> lyrsrie>raegti(, hs r); e r =s t a a o r e p a e ) r   eDtSuc(lyr; } } r t r  e r eun r; } Look at the line : sp<IMediaPlayer> player(service->create(getpid(), this, url)); It actually takes the help of the IMediaPlayerservice layer and calls the create function on this. This function can be found in basemedialibmediaIMediaPlayerService.cpp file. The create function of the MediaPlayerService looks like the following. It can be found at basemedialibmediaplayerserviceMediaPlayerService.cpp. sp<IMediaPlayer> MediaPlayerService::create(pid_t pid, const s < M d a l y r  M d a l y r e v c : c e t ( i _  p d c n ts < M d a l y r l e t & pIeiPae> eiPaeSrie:raepdt i, os  pIeiPaeCin> c i n , c n tc a *u l let os  hr  r) { i t 2 tc n I =a d o d a o i _ n ( m e t o n d ; n3_  ond   nri_tmcic&NxCnI) s < l e t  c =n wC i n ( h s p d c n I , c i n ) pCin>   e  letti, i, ond let; LG(Cet nwcin(d fo pd%,ul%,cnI=d,cnI,pd ul cnI) OV"rae e let%) rm i d r=s ond%" ond i, r, ond; i  ( O E R R !  c > e D t S u c ( r ) f N_RO = -staaoreul) { ccer) .la(; r t r  c eun ; } w < l e t  w =c pCin>   ; Mtx:uooklc(Lc) ue:Atlc okmok; mlet.d() Cinsadw; r t r  c eun ; } Look at the line : sp<Client> c = new Client(this, pid, connId, client) The client constructor is as the following: s < M d a l y r  M d a l y r e v c : c e t ( i _  p d c n ts < M d a l y r l e t & pIeiPae> eiPaeSrie:raepdt i, os  pIeiPaeCin> c i n , c n tc a *u l let os  hr  r) { i t 2 tc n I =a d o d a o i _ n ( m e t o n d ; n3_  ond   nri_tmcic&NxCnI) s < l e t  c =n wC i n ( h s p d c n I , c i n ) pCin>   e  letti, i, ond let;
  • 4. LG(Cet nwcin(d fo pd%,ul%,cnI=d,cnI,pd ul cnI) OV"rae e let%) rm i d r=s ond%" ond i, r, ond; i  ( O E R R !  c > e D t S u c ( r ) f N_RO = -staaoreul) { ccer) .la(; r t r  c eun ; } w < l e t  w =c pCin>   ; Mtx:uooklc(Lc) ue:Atlc okmok; mlet.d() Cinsadw; r t r  c eun ; } Now look at the following line (line number 6) of sp<IMediaPlayer> MediaPlayerService::create(pid_t pid, const sp<IMediaPlayerClient>& client, const char* url) if (NO_ERROR != c->setDataSource(url)) So we are basically calling the setDataSource on the Client. This function is like the following: s a u _  M d a l y r e v c : C i n : s t a a o r e c n tc a  * r ) ttst eiPaeSrie:let:eDtSuc(os  hr ul { LG(staaore%),ul; OV"eDtSuc(s" r) i  ( r =  N L ) f ul = UL r t r  U K O N E R R eun NNW_RO; i  ( t n m ( r , " o t n : / , 1 ) =  0 { f srcpul cnet/" 0 = ) / gtafldsrpo frtecnetUiad / e ieecitr o h otn r n / ps i t testaaoref)mto / as t o h eDtSuc(d ehd Srn1 ul6ul; tig6 r1(r) i tf =a d o d : p n o t n P o i e F l ( r 1 ) n  d   nri:oeCnetrvdrieul6; i  ( d <0 f f   ) { LG(Cud' oe f fr%" ul; OE"olnt pn d o s, r) r t r  U K O N E R R eun NNW_RO; } staaoref,0 07ffffL) / ti st mtts eDtSuc(d , xfffffL; / hs es Sau coef) ls(d; r t r  m t t s eun Sau; } e s  { le p a e _ y e p a e T p =g t l y r y e u l ; lyrtp lyrye   ePaeTp(r) LG(pae tp =%" paeTp) OV"lyr ye d, lyrye; / cet tergttp o pae / rae h ih ye f lyr s < e i P a e B s >p =c e t P a e ( l y r y e ; pMdalyrae    raelyrpaeTp) i  ( =  N L ) r t r  N _ N T f p = UL eun OII; i  ( p > a d a e u p t ) { f !-hrwrOtu()
  • 5. m u i O t u =n wA d o u p t ) Adoupt   e  uiOtu(; sai_atMdalyrnefc*(.e()>eAdoikmuiOtu) ttccs<eiPaeItrae>pgt)-stuiSn(Adoupt; } / nwstdt suc / o e aa ore LG( staaore) OV" eDtSuc"; m t t s =p > e D t S u c ( r ) Sau   -staaoreul; i  ( S a u =  N _ R O ) m l y r =p f mtts = OERR Pae   ; r t r  m t t s eun Sau; } } From the above code snippet it becomes clear that either we do i  ( t n m ( r , " o t n : / , 1 ) =  0 { f srcpul cnet/" 0 = ) / gtafldsrpo frtecnetUiad / e ieecitr o h otn r n / ps i t testaaoref)mto / as t o h eDtSuc(d ehd Srn1 ul6ul; tig6 r1(r) i tf =a d o d : p n o t n P o i e F l ( r 1 ) n  d   nri:oeCnetrvdrieul6; i  ( d <0 f f   ) { LG(Cud' oe f fr%" ul; OE"olnt pn d o s, r) r t r  U K O N E R R eun NNW_RO; } staaoref,0 07ffffL) / ti st mtts eDtSuc(d , xfffffL; / hs es Sau coef) ls(d; r t r  m t t s eun Sau; ● ● or we do the following: e s  { le p a e _ y e p a e T p =g t l y r y e u l ; / h r i e t a t t e P a e T p f o lyrtp lyrye   ePaeTp(r) /ee t xrcs h lyr ye rm teUL h R. LG(pae tp =%" paeTp) OV"lyr ye d, lyrye; / cet tergttp o pae / rae h ih ye f lyr s < e i P a e B s >p =c e t P a e ( l y r y e ; pMdalyrae    raelyrpaeTp) ....... ....... ....... ....... I t e f r t c s  t e s t a a o r e ( i e 1 ) f n t o l o s l k t e f l o i g n h is ae h eDtSuc ln 2 ucin ok ie h olwn: s a u _  M d a l y r e v c : C i n : s t a a o r e i tf , i t 4 to f e , i t 4 tl n t ) ttst eiPaeSrie:let:eDtSuc(n  d n6_  fst n6_  egh {
  • 6. LG(staaoref=d ofe=ld lnt=ld,f,ofe,lnt) OV"eDtSuc d%, fst%l, egh%l" d fst egh; s r c  s a s ; tut tt b i tr t =f t t f , & b ; n  e   sa(d s) i  ( e !  0 { f rt = ) LG(ftt%)fie:%,%" f,rt srro(rn); OE"sa(d ald d s, d e, terrero) r t r  U K O N E R R eun NNW_RO; } LG(s_e =%l" s.tdv; OV"tdv lu, bs_e) LG(s_oe=%" s.tmd) OV"tmd u, bs_oe; LG(s_i =%u,s.tud; OV"tud l" bs_i) LG(s_i =%u,s.tgd; OV"tgd l" bs_i) LG(s_ie=%l" s.tsz) OV"tsz lu, bs_ie; i  ( f s t >  s . t s z ) { f ofe = bs_ie LG(ofe err) OE"fst ro"; :coef) :ls(d; r t r  U K O N E R R eun NNW_RO; } i  ( f s t +l n t >s . t s z ) { f ofe   egh   bs_ie l n t =s . t s z -o f e ; egh   bs_ie   fst LG(cluae lnt =%l" lnt) OV"acltd egh ld, egh; } p a e _ y e p a e T p =g t l y r y e f , o f e , l n t ) / h r i g t t e f l t p lyrtp lyrye   ePaeTp(d fst egh; /ee t es h ie ye fo teFl dsrpo rm h ie ecitr LG(pae tp =%" paeTp) OV"lyr ye d, lyrye; / cet tergttp o pae / rae h ih ye f lyr s < e i P a e B s >p =c e t P a e ( l y r y e ; pMdalyrae    raelyrpaeTp) i  ( =  N L ) r t r  N _ N T f p = UL eun OII; i  ( p > a d a e u p t ) { f !-hrwrOtu() m u i O t u =n wA d o u p t ) Adoupt   e  uiOtu(; sai_atMdalyrnefc*(.e()>eAdoikmuiOtu) ttccs<eiPaeItrae>pgt)-stuiSn(Adoupt; } / nwstdt suc / o e aa ore m t t s =p > e D t S u c ( d o f e , l n t ) Sau   -staaoref, fst egh; i  ( S a u =  N _ R O ) m l y r =p f mtts = OERR Pae   ; r t r  m t t s eun Sau; } Look at the line : sp<MediaPlayerBase> p = createPlayer(playerType). It becomes clear that we create the player here. The sp<MediaPlayerBase> p = createPlayer (playerType) actually creates the right player.
  • 7. In the second case (the else part) we call sp<MediaPlayerBase> p = createPlayer(playerType) at line 6. We extract the file type from the URL. This helps us in creating the right player object. The createPlayer function looks like the following: s < e i P a e B s >M d a l y r e v c : C i n : c e t P a e ( l y r t p p a e T p ) pMdalyrae  eiPaeSrie:let:raelyrpae_ye lyrye { / dtriei w hv tergtpae tp / eemn f e ae h ih lyr ye s < e i P a e B s >p =m l y r pMdalyrae    Pae; i  ( p !  N L ) &  ( - p a e T p ( !  p a e T p ) { f ( = UL & p>lyrye) = lyrye) LG(dlt pae"; OV"eee lyr) pcer) .la(; } i  ( =  N L ) { f p = UL p =a d o d : r a e l y r p a e T p , t i , n t f )   nri:cetPae(lyrye hs oiy; } r t r  p eun ; } Hence it actually delegates the task to p = android::createPlayer(playerType, this, notify); The above function is as follows; s a i  s < e i P a e B s >c e t P a e ( l y r t p p a e T p , v i *c o i , ttc pMdalyrae  raelyrpae_ye lyrye od  oke ntf_alakfntfFn) oiyclbc_ oiyuc { s < e i P a e B s >p pMdalyrae  ; s i c  ( l y r y e { wth paeTp) #fdfN_PNOE ine OOECR c s  P _ L Y R ae VPAE: LG( cet PPae"; OV" rae Vlyr) p =n wP P a e ( ;   e  Vlyr) bek ra; #ni edf c s  S N V X P A E : ae OIO_LYR LG( cet MdFl"; OV" rae iiie) p =n wM d F l ( ;   e  iiie) bek ra; c s  V R I _ L Y R ae OBSPAE: LG( cet VriPae"; OV" rae obslyr) p =n wV r i P a e ( ;   e  obslyr) bek ra; } i  ( !  N L ) { f p = UL i  ( - i i C e k ) =  N _ R O ) { f p>nthc( = OERR p>eNtfClbc(oke ntfFn) -stoiyalakcoi, oiyuc; } e s  { le pcer) .la(; }
  • 8. } i  ( =  N L ) { f p = UL LG(Fie t cet pae ojc"; OE"ald o rae lyr bet) } r t r  p eun ; } Thus we find that the right player is created through the parameterized factory function createPlayer. i hope this explains how the right mediaplayer is created from the Uri passed in the Java client side interface of the Mediaplyer.