Android Question Convert code

gballa

Member
Licensed User
Anyone know how to convert this code to B4A

// stop music player
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.requestAudioFocus(null,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

//resume music player

am.abandonAudioFocus(null);


I am trying to pause any music player that is installed on the users system.

Thanks
 

Star-Dust

Expert
Licensed User
Longtime User
B4X:
#IF JAVA
   // stop music player
   AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
   am.requestAudioFocus(null,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
#END IF

B4X:
#IF JAVA
   //resume music player
   am.abandonAudioFocus(null);
#END IF

See this: https://www.b4x.com/android/forum/threads/inline-java-code.50141/#content
 
Upvote 0

gballa

Member
Licensed User
B4X:
#IF JAVA
   // stop music player
   AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
   am.requestAudioFocus(null,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
#END IF

B4X:
#IF JAVA
   //resume music player
   am.abandonAudioFocus(null);
#END IF

See this: https://www.b4x.com/android/forum/threads/inline-java-code.50141/#content


Thank you for the code, but I seem to be getting an error

B4A Version: 8.30
Parsing code. (0.00s)
Compiling code. (0.05s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Generating R file. (0.10s)
Compiling generated Java code. Error
B4A line: 22
End Sub
javac 1.8.0_60
src\b4a\example\main.java:390: error: <identifier> expected
am.requestAudioFocus(null,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
^
1 error


not sure how to fix this
 
Upvote 0
Top