An warware: yadda ake madauki javafx media player

yadda ake madauki media player A cikin duniyar kafofin watsa labaru na zamani, ikon madauki mai kunna watsa labarai ya zama abin da ake nema sosai. Wannan gaskiya ne musamman ga waษ—ancan lokutan da ba za mu iya samun isassun waฦ™a, bidiyo ko kowace hanyar sadarwa da muke jin daษ—in gaske ba. Maษ“allin mai kunna watsa labarai yana tabbatar da cewa abun cikin yana ci gaba da wasa, yana bawa masu amfani damar jin daษ—in sa ba tare da sake kunna shi da hannu ba. Wannan labarin yana magana ne akan yadda ake madauki na'urar mai jarida ta amfani da Java, sanannen yaren shirye-shirye, tare da zurfin jagorar mataki-mataki kan coding mafita. Bari yanzu mu nutse cikin looping na'urar mai jarida kuma mu bincika ษ—akunan karatu da ayyukan da ke cikin wannan tsari.

Amfani da Tsarin Media na Java (JMF) don madauki

Tsarin Watsa Labarai na Java (JMF) babban ษ—akin karatu ne mai ฦ™arfi wanda ke ba da damar haษ“aka aikace-aikacen multimedia a Java. Yana ba da tallafi don sauti, bidiyo, da sauran kafofin watsa labarai na lokaci, yana mai da shi kyakkyawan zaษ“i don aiwatar da ayyukan looping a cikin na'urar mai jarida. A cikin wannan sashe, za mu shiga cikin ษ—akin karatu na JMF kuma mu tattauna yadda ake madauki abun cikin kafofin watsa labarai ta amfani da bayanin mataki-mataki na lambar.

import javax.media.*;
import java.net.*;

public class MediaPlayerLooper {
    public static void main(String[] args) {
        try {
            // Create a media locator from a file URL
            MediaLocator mediaLocator = new MediaLocator(new URL("file:///path/to/media/file"));

            // Create a Player from the media locator
            Player player = Manager.createPlayer(mediaLocator);

            // Add a controller listener to the player
            player.addControllerListener(new ControllerAdapter() {
                @Override
                public void endOfMedia(EndOfMediaEvent e) {
                    // Set media time to zero and restart the player
                    player.setMediaTime(new Time(0));
                    player.start();
                }
            });

            // Start playing the media
            player.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Snippet ษ—in lambar da ke sama yana nuna matakai masu zuwa:

1. Shigo da JMF da sauran dakunan karatu masu mahimmanci
2. ฦ˜irฦ™irar MediaPlayerLooper class
3. Yi amfani da MediaLocator don ฦ™irฦ™irar abu mai jarida
4. ฦ˜irฦ™irar Dan wasa ta amfani da Manager aji tare da ฦ™ayyadadden abin watsa labarai
5. aara a Mai Sauraron Sarrafa ga mai kunnawa don lura da canje-canjen jiharsa
6. Gudanar da taron 'endOfMedia', wanda ke faruwa lokacin da kafofin watsa labaru suka gama kunnawa, ta hanyar sake saita lokacin watsa labarai zuwa sifili da sake kunna mai kunnawa.
7. Fara kunna kafofin watsa labarai

Zazzagewa tare da MediaPlayer a cikin JavaFX

JavaFX wani mashahurin ษ—akin karatu ne don ฦ™irฦ™irar aikace-aikacen multimedia a Java. Nasa mai jarida aji yana ba da ginanniyar aikin madauki, yana mai da shi mafi sauฦ™i don madauki fayilolin mai jarida. A cikin wannan sashe, za mu bincika yin amfani da MediaPlayer na JavaFX don madauki abun cikin mai jarida.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import java.io.File;

public class JavaFXMediaPlayerLooper extends Application {
    @Override
    public void start(Stage primaryStage) {
        File mediaFile = new File("path/to/media/file");
        Media media = new Media(mediaFile.toURI().toString());
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
        MediaView mediaView = new MediaView(mediaPlayer);

        StackPane root = new StackPane();
        root.getChildren().add(mediaView);
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setTitle("Media Player Looper");
        primaryStage.setScene(scene);
        primaryStage.show();

        mediaPlayer.play();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Misalin lambar JavaFX da ke sama yana gabatar da matakai masu zuwa:

1. Shigo da ษ—akunan karatu na JavaFX
2. ฦ˜irฦ™irar JavaFXMediaPlayerLooper class mikawa daga Aikace-aikace
3. Load da fayilolin mai jarida ta amfani da kafofin watsa labaru, class
4. ฦ˜irฦ™irar mai jarida abu tare da ษ—imbin kafofin watsa labarai
5. Saita cycleCount sifa ta MediaPlayer zuwa BAYANI domin looping
6. ฦ˜irฦ™irar MediaView abu kuma ฦ™ara shi zuwa hoton wurin
7. Fara abubuwan haษ—in mai amfani, kamar mataki da fage
8. Fara kunna kafofin watsa labarai

A taฦ™aice, ana iya samun madaidaicin mai kunna mai jarida a Java ta amfani da dakunan karatu kamar JMF da JavaFX. Ta hanyar fahimtar ayyuka da azuzuwan da waษ—annan ษ—akunan karatu ke bayarwa, masu haษ“akawa na iya ฦ™irฦ™irar ingantattun aikace-aikace masu jan hankali waษ—anda ke biyan buฦ™atun kafofin watsa labarai na masu amfani.

Shafi posts:

Leave a Comment