Android Kotlin - How to loop video after exiting another activity? - kotlin

My app is working, and the main screen, you see 3 buttons with a videobackground in loop, after open a activity from button, I go back to main screen and the video is not playing.
videoView = findViewById(R.id.videoViewbg)
videoView!!.setVideoURI(Uri.parse("android.resource://" + packageName + "/" + R.raw.menu))
videoView!!.requestFocus()
videoView!!.start()
videoView!!.setOnPreparedListener { mp ->
true.also { mp.isLooping = it }
}
videoView!!.setOnCompletionListener { mp ->
true.also { mp.start() }
}

Related

Open web page on click at a button in a JetBrains Space chat message using Kotlin SDK

I have a simple chat bot that renders "on this day" facts based on Wikipedia.
As you can see, there's a button on my UI. I want that if the user taps on it, a new browser tab opens with given Wikipedia url.
Until now, I only see the possibility to send other messages using buttons and there action (PostMessageAction).
Do you have any tip on how to achieve my feature idea?
Code
private fun makeMessage(container: OnThisDay): ChatMessage {
return message {
...
section {
text("On this day (${container.date}) happened:")
container.happenings.reversed().forEach {
text(
size = MessageTextSize.SMALL,
content = "${it.year}:\n${it.description}",
)
controls {
wikipediaButton(it.wikipediaUrl) <-- BUTTON
}
divider()
}
}
}
}
private fun MessageControlGroupBuilder.wikipediaButton(urlString: String) {
val action = PostMessageAction("a", "b") <-- NO other action possible?
button("Open Wikipedia", action, MessageButtonStyle.SECONDARY)
}
Screenshot
You can use NavigateUrlAction for this. Here's an example:
message {
section {
controls {
button(
text = "Open Wikipedia",
style = MessageButtonStyle.PRIMARY,
action = NavigateUrlAction(
url = "https://wikipedia.org",
withBackUrl = false,
openInNewTab = true
)
)
}
}
}

How to update the map properly using canvas and a button when the players relocate to a new location?

My game snapshot Attachment> Blockquote
My canvas constructs
public class DrawingView4 extends View{
DrawingView4(Context context4)
{
super(context4);
}
#Override protected void onDraw(Canvas canvas4)
{
int tile4=0;
if (DoneDrawFacilities && doneloading) {
}
else {
for (int i4=0; i4< 17 && notfixingorientation; i4++){
if (i4< 16) {
for (int ii4=0; ii4 < 16; ii4++){
try {
//Checking the data of all spots of the game map from package directory.
//Then Draw in canvas if the data of the spot occupied by type of human and core facilities,
FacilityList = new Gson().fromJson(FileUtil.readFile(FileUtil.getPackageDataDir(getApplicationContext()).concat("/GameResource/Tile".concat(String.valueOf((long)(tile4 + 1)).concat(".data")))), new TypeToken<ArrayList<HashMap<String, Object>>>(){}.getType());
if (FacilityList.get((int)0).get("Type").toString().equals("Human")) {
canvas4.drawBitmap(BitmapFactory.decodeFile(AllObjects.getString(String.valueOf((long)(tile4)), "")),null,new Rect(ii4*120, i4*120, 120*(ii4+1),120*(i4+1)), null);
}
if (FacilityList.get((int)0).get("Type").toString().equals("Core")) {
if (FacilityList.get((int)0).get("Name").toString().equals("Arena")) {
canvas4.drawBitmap(BitmapFactory.decodeFile(AllObjects.getString(String.valueOf((long)(tile4)), "")),null,new Rect(7*120, 7*120, 120*(8+1),120*(8+1)), null);
}
else {
}
}
} catch (Exception e) {
}
FacilityList.clear();
tile4++;
}
}
else {
DoneDrawFacilities = true;
}
}
}
}}
Blockquote
My Relocate button
//I use sharepreference called AllObjects rather than a list and I Only update the path of objects in specific tile in sharedpreference such as in variable 1, 2, etc. and then re-draw using this code below, next time I update the objects path and get this object path from the same json file in the package directory. Too decode to Bitmap and then Draw in canvas.
//Some other code are removed that just updating some data in specific file directory.
AA_structures_facilities.removeAllViews();
AA_structures_facilities.addView(new DrawingView4(GameActivity.this));
// But It freezes the screen or stop me from touching the touch event in a second everytime I update new canvas.
//WHILE MY touchevent is hundled in the parent LinearLayout where the canvas is placed.

PagerAdapter always getting called two times in ViewPager

I am trying to make a slider between TouchImageView and PlayerView (Exoplayer) but I am unable to catch up with certain issues that are persisting even after several changes. All the suggestions and answers are welcome. Pardon my questioning skills and please let me know if more inputs are needed for your analysis. Kindly also let me know if there is any other alternative to successfully meet my expectations of properly implementing views smoothly in ViewPager.
Problem description:-
Issues related to click on view :-
When the image is clicked, the audio of next video (if any) starts playing in background.
The same issue is with PlayerView. When the video thumbnail is clicked, the audio of clicked video as well as next video plays together.
Issues related to slider :-
When an we slide and reach to an image preceding to a video, the audio starts playing in background. However, after sliding once toward video and sliding again in forward or backward direction from video for once, the audio stops. But this issue persists after viewing more than one images in forward or backward direction of video.
Attempts made by me to solve this issue :-
I tried to use playerView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {...}) method in PagerAdapter to handle player states while sliding between views. Unfortunately, I was unable to grasp to use different player states.
I also tried to use viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {...} method in StatusViewer class.
StatusViewer Java class (Setting PagerAdapter class object inViewPager) :-
modelFeedArrayList = (ArrayList<File>) getIntent().getSerializableExtra("modelFeedArrayList");
position = intent.getIntExtra("position", 0);
ImageSlideAdapter imageSlideAdapter = new ImageSlideAdapter(this,modelFeedArrayList,position);
viewPager.setAdapter(imageSlideAdapter);
viewPager.setCurrentItem(position);
viewPager.setOffscreenPageLimit(0);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
File currentFile = modelFeedArrayList.get(position);
String filePath = currentFile.toString();
if (filePath.endsWith(".jpg") || currentPage == position){
currentPage = position;
ImageSlideAdapter.player.pause();
}
else {
currentPage = position;
ImageSlideAdapter.player.play();
}
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
ImageSliderAdapter (PagerAdapter) (code mentioned below is inside instantiateItem):-
File currentFile = modelFeedArrayList.get(position);
String filePath = currentFile.toString();
if (currentFile.getAbsolutePath().endsWith(".mp4")) {
statusImageView.setVisibility(View.GONE);
playerView.setVisibility(View.VISIBLE);
player = new ExoPlayer.Builder(context).build();
MediaItem mediaItem = MediaItem.fromUri(filePath);
player.addMediaItem(mediaItem);
playerView.setPlayer(player);
player.prepare();
playerView.setBackgroundColor(context.getResources().getColor(android.R.color.black));
playerView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
#Override
public void onViewAttachedToWindow(View v) {
Log.d("Filepath", filePath);
Log.d("Position", "" + position);
}
#Override
public void onViewDetachedFromWindow(View v) {
if (filePath.endsWith(".jpg") || currentPage == position || modelFeedArrayList.get(currentPage).getAbsolutePath().endsWith(".jpg")){
currentPage = position;
player.pause();
Objects.requireNonNull(playerView.getPlayer()).pause();
}
else {
player.release();
Objects.requireNonNull(playerView.getPlayer()).release();
}
}
});
} else {
playerView.setVisibility(View.GONE);
statusImageView.setVisibility(View.VISIBLE);
Glide.with(context).load(modelFeedArrayList.get(position)).into(statusImageView);
statusImageView.setBackgroundColor(context.getResources().getColor(android.R.color.black));
}
Objects.requireNonNull(container).addView(itemView);
return itemView;
}
#Override
public void destroyItem(#NonNull #NotNull ViewGroup container, int position, #NonNull #NotNull Object object) {
container.removeView((ConstraintLayout) object);
}
Thank you StackOverflow community for viewing this question. I resolved the above issue by below mentioned modifications :-
Changes in ImageSliderAdapter (PagerAdapter) :-
-> Below mentioned code was added in onViewAttachedToWindow(View v) :-
if (filePath.endsWith(".jpg") || currentPage == position || modelFeedArrayList.get(currentPage).getAbsolutePath().endsWith(".jpg")){
currentPage = position;
player.pause();
Objects.requireNonNull(playerView.getPlayer()).pause();
}
else {
player.pause();
Objects.requireNonNull(playerView.getPlayer()).pause();
if (filePath.endsWith(".mp4")){
player.pause();
Objects.requireNonNull(playerView.getPlayer()).pause();
}
else {
player.play();
Objects.requireNonNull(playerView.getPlayer()).play();
}
}
-> Below mentioned code was added in onViewDetachedFromWindow(View v) :-
if (filePath.endsWith(".mp4")){
player.release();
Objects.requireNonNull(playerView.getPlayer()).release();
}
-> player.play() was added after player.prepare().
Changes in StatusViewer Java class :-
-> The below changes cured the issue of player malfunctioning and player's play state and release state. I used the smoothScroll: false in setCurrentItem.
viewPager.setCurrentItem(position,false);

AdMob test Ad displays but has a download button. Anyone know why it is happing

I am getting a download button displaying in the middle of my test ad. The test ad displays but then when I click on it the download button pops up and I need to click it in order to open the ad link. Anyone know why it is happening.
var interstitial: GADInterstitial!
override func didMove(to view: SKView) {
interstitial = createAndLoadInterstitial()
}
func createAndLoadInterstitial() -> GADInterstitial {
let interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
interstitial.delegate = self
interstitial.load(GADRequest())
return interstitial
}
// Run Code here that you want after Ad closes like a restart game func.
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitial = createAndLoadInterstitial()
countStartPressed = 0
GameHandler.sharedInstance.startPressed = countStartPressed
restart()
}
// Update the countStartPressed here and save it to gameData
// CountStartPressed is the number of time the start game button is pressed in the gameOverScene
override func update(_ currentTime: TimeInterval) {
countStartPressed = GameHandler.sharedInstance.startPressed
if countStartPressed == 1 {
if (self.interstitial.isReady) {
self.interstitial.present(fromRootViewController (self.view?.window!.rootViewController)!)
} else {
print("Ad wasn't ready")
}
}
}

Eclipse update the statusbar

I'm working on Eclipse plugin and I add an 16x16 icon to the statusbar by
ToolBarManager manager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
manager.add(updatingNewsAction);
Where updatingNewsAction is a class that extends org.eclipse.jface.action.Action.
However I've got problem with removing the updatingNewsAction from the toolbar. It's removed, but I can see that only when something updates the statusbar - for example minimazing/maximazing the borderline views. Then after reading some blog post I've wrote:
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IWorkbenchPart part = page.getActivePart();
IWorkbenchPartSite site = part.getSite();
IViewSite vSite = (IViewSite) site;
IActionBars actionBars = vSite.getActionBars();
if (actionBars == null) {
return;
}
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
if (statusLineManager == null) {
return;
}
statusLineManager.update(true);
}
});
Which is a step forward, because it gets updated when switching focus between views, but still it doesn't happen immediately and without user interactions. How to update the status bar programmatically immediately?